From: Johannes Date: Sun, 22 May 2011 09:39:49 +0000 (+0200) Subject: Support relative redirects. Fixes #36 X-Git-Tag: v0.4.1^2~12^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8aa6fabd4d57ca0f9a5efc4a7d70fec338c94e2a;p=services%2Fpython-requests.git Support relative redirects. Fixes #36 --- diff --git a/requests/models.py b/requests/models.py index 3a00d8c..2c3241d 100644 --- a/requests/models.py +++ b/requests/models.py @@ -177,6 +177,12 @@ class Request(object): url = r.headers['location'] + # Facilitate for non-RFC2616-compliant 'location' headers + # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource') + if not urlparse(url).netloc: + parent_url_components = urlparse(self.url) + url = '%s://%s/%s' % (parent_url_components.scheme, parent_url_components.netloc, url) + # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 if r.status_code is 303: method = 'GET'