From e2645826be0449842dcc812e31541c5254c69e05 Mon Sep 17 00:00:00 2001 From: Chris Dary Date: Tue, 28 Feb 2012 12:08:37 -0500 Subject: [PATCH 1/4] Decode URL to utf-8 before joining. To avoid UnicodeDecodeError's like on http://blip.fm/~1abvfu --- requests/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/requests/models.py b/requests/models.py index 8368c9fb..aea77237 100644 --- a/requests/models.py +++ b/requests/models.py @@ -227,6 +227,8 @@ class Request(object): # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource') if not urlparse(url).netloc: + if not isinstance(url, unicode): + url = url.decode('utf-8', 'ignore') url = urljoin(r.url, url) # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 From fba77fc65f40ba10428346c0d01fe6c5d55ddbce Mon Sep 17 00:00:00 2001 From: Chris Dary Date: Thu, 8 Mar 2012 13:10:18 -0800 Subject: [PATCH 2/4] Potential fix for #436 --- requests/models.py | 3 +++ tests/test_requests.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/requests/models.py b/requests/models.py index 4e747c84..73176e71 100644 --- a/requests/models.py +++ b/requests/models.py @@ -675,6 +675,9 @@ class Response(object): while 1: #XXX correct line size? (httplib has 64kb, seems insane) pending_bytes = fp.readline(40).strip() + if pending_bytes == '': + # No content, like a HEAD request. Break out. + break pending_bytes = int(pending_bytes, 16) if pending_bytes == 0: break diff --git a/tests/test_requests.py b/tests/test_requests.py index d70899f7..8c994f80 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -797,7 +797,10 @@ class RequestsTestSuite(TestSetup, unittest.TestCase): r = requests.get(httpbin('status', '404')) r.text - + def test_chunked_head_redirect(self): + u = "http://t.co/NFrx0zLG" + r = requests.head(u, allow_redirects=True) + self.assertEqual(r.status_code, 200) if __name__ == '__main__': unittest.main() From 0e65dff008f8d18fd6545d4b3e1656e048f3306d Mon Sep 17 00:00:00 2001 From: Chris Dary Date: Thu, 8 Mar 2012 13:22:38 -0800 Subject: [PATCH 3/4] Remove unnecessary bit from previous branch. This reverts commit e2645826be0449842dcc812e31541c5254c69e05. --- requests/models.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/requests/models.py b/requests/models.py index 73176e71..23c04b11 100644 --- a/requests/models.py +++ b/requests/models.py @@ -227,8 +227,6 @@ class Request(object): # Facilitate non-RFC2616-compliant 'location' headers # (e.g. '/path/to/resource' instead of 'http://domain.tld/path/to/resource') if not urlparse(url).netloc: - if not isinstance(url, unicode): - url = url.decode('utf-8', 'ignore') url = urljoin(r.url, url) # http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.4 From bd0e00280460b28d3bf715d64888605750d9e735 Mon Sep 17 00:00:00 2001 From: Chris Dary Date: Thu, 8 Mar 2012 14:44:07 -0800 Subject: [PATCH 4/4] Move chunked head redirect test to ext --- tests/test_requests.py | 5 ----- tests/test_requests_ext.py | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_requests.py b/tests/test_requests.py index 8c994f80..6aefd805 100755 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -797,10 +797,5 @@ class RequestsTestSuite(TestSetup, unittest.TestCase): r = requests.get(httpbin('status', '404')) r.text - def test_chunked_head_redirect(self): - u = "http://t.co/NFrx0zLG" - r = requests.head(u, allow_redirects=True) - self.assertEqual(r.status_code, 200) - if __name__ == '__main__': unittest.main() diff --git a/tests/test_requests_ext.py b/tests/test_requests_ext.py index 1e25dbe6..2102a5ea 100644 --- a/tests/test_requests_ext.py +++ b/tests/test_requests_ext.py @@ -53,6 +53,12 @@ class RequestsTestSuite(unittest.TestCase): url = u'http://blip.fm/~1abvfu' requests.get(url) + + def test_chunked_head_redirect(self): + url = "http://t.co/NFrx0zLG" + r = requests.head(url, allow_redirects=True) + self.assertEqual(r.status_code, 200) + if __name__ == '__main__': unittest.main()