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()