* @param string $url optional URL
*
* @return CurlResult a CURL with error response
+ * @throws InternalServerErrorException
*/
public static function createErrorCurl($url = '')
{
}
if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode== 307) {
- $redirect_parts = parse_url($this->info['redirect_url']);
- if (preg_match('/(Location:|URI:)(.*?)\n/i', $this->header, $matches)) {
- $redirect_parts = array_merge($redirect_parts, parse_url(trim(array_pop($matches))));
+ $redirect_parts = parse_url(defaults($this->info, 'redirect_url', ''));
+ if (empty($redirect_parts)) {
+ $redirect_parts = [];
}
- $parts = parse_url($this->info['url']);
+ if (preg_match('/(Location:|URI:)(.*?)\n/i', $this->header, $matches)) {
+ $redirect_parts2 = parse_url(trim(array_pop($matches)));
+ if (!empty($redirect_parts2)) {
+ $redirect_parts = array_merge($redirect_parts, $redirect_parts2);
+ }
+ }
- if (empty($redirect_parts['scheme']) && !empty($parts['scheme'])) {
- $redirect_parts['scheme'] = $parts['scheme'];
+ $parts = parse_url(defaults($this->info, 'url', ''));
+ if (empty($parts)) {
+ $parts = [];
}
- if (empty($redirect_parts['host']) && !empty($parts['host'])) {
- $redirect_parts['host'] = $parts['host'];
+ /// @todo Checking the corresponding RFC which parts of a redirect can be ommitted.
+ $components = ['scheme', 'host', 'path', 'query', 'fragment'];
+ foreach ($components as $component) {
+ if (empty($redirect_parts[$component]) && !empty($parts[$component])) {
+ $redirect_parts[$component] = $parts[$component];
+ }
}
$this->redirectUrl = Network::unparseURL($redirect_parts);
- $this->isRedirectUrl = filter_var($this->redirectUrl, FILTER_VALIDATE_URL) !== false;
+ $this->isRedirectUrl = true;
} else {
$this->isRedirectUrl = false;
}