From 01b2ec9964aada45ef54274a36b42cf8461fb2ce Mon Sep 17 00:00:00 2001 From: ozh Date: Mon, 10 Feb 2014 21:32:27 +0100 Subject: [PATCH 1/3] Follow relative redirects Should fix #102 --- library/Requests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Requests.php b/library/Requests.php index 854491b81..887f07b79 100755 --- a/library/Requests.php +++ b/library/Requests.php @@ -595,7 +595,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data } $options['redirected']++; $location = $return->headers['location']; - if (strpos ($location, '/') === 0) { + if (strpos ($location, 'http') !== 0) { // relative redirect, for compatibility make it absolute $location = Requests_IRI::absolutize($url, $location); $location = $location->uri; From 288d63099ba33d6b1a03b762ff0a75eca2ef206d Mon Sep 17 00:00:00 2001 From: ozh Date: Tue, 11 Feb 2014 08:03:47 +0100 Subject: [PATCH 2/3] Explicitly check for leading `http(s)://` in URL --- library/Requests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Requests.php b/library/Requests.php index 887f07b79..2289279d6 100755 --- a/library/Requests.php +++ b/library/Requests.php @@ -595,7 +595,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data } $options['redirected']++; $location = $return->headers['location']; - if (strpos ($location, 'http') !== 0) { + if (strpos ($location, 'http://') !== 0 || strpos ($location, 'https://') !== 0) { // relative redirect, for compatibility make it absolute $location = Requests_IRI::absolutize($url, $location); $location = $location->uri; From 35f235b3f92e76862f5abd7806ca045fff887739 Mon Sep 17 00:00:00 2001 From: ozh Date: Tue, 11 Feb 2014 08:14:48 +0100 Subject: [PATCH 3/3] Test AND, not OR --- library/Requests.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/Requests.php b/library/Requests.php index 2289279d6..afeff666b 100755 --- a/library/Requests.php +++ b/library/Requests.php @@ -595,7 +595,7 @@ protected static function parse_response($headers, $url, $req_headers, $req_data } $options['redirected']++; $location = $return->headers['location']; - if (strpos ($location, 'http://') !== 0 || strpos ($location, 'https://') !== 0) { + if (strpos ($location, 'http://') !== 0 && strpos ($location, 'https://') !== 0) { // relative redirect, for compatibility make it absolute $location = Requests_IRI::absolutize($url, $location); $location = $location->uri;