From c22b71fc5b69736f40f8e491c5a6c4db461321f3 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Je=CC=81re=CC=81my=20Bethmont?= Date: Wed, 17 Aug 2011 16:04:53 +0200 Subject: [PATCH] Handle redirection without scheme. --- requests/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/requests/models.py b/requests/models.py index cc9cc6f..931bafd 100644 --- a/requests/models.py +++ b/requests/models.py @@ -225,6 +225,11 @@ class Request(object): url = r.headers['location'] + # Handle redirection without scheme (see: RFC 1808 Section 4) + if url.startswith('//'): + parsed_rurl = urlparse(r.url) + url = '%s:%s' % (parsed_rurl.scheme, url) + # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource') if not urlparse(url).netloc: -- 2.7.4