Skip to content

Commit ce4063b

Browse files
author
Eivind Uggedal
committed
Do not read the response of HEAD requests as httplib seems to be blocking.
1 parent aad2127 commit ce4063b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎httplib2/__init__.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,9 @@ def _conn_request(self, conn, request_uri, method, body, headers):
860860
else:
861861
raise
862862
else:
863-
content=response.read()
863+
content=""
864+
ifmethod!="HEAD":
865+
content=response.read()
864866
response=Response(response)
865867
ifmethod!="HEAD":
866868
content=_decompressContent(response, content)

‎httplib2test.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,14 @@ def testHeadGZip(self):
556556
self.assertNotEqual(int(response['content-length']), 0)
557557
self.assertEqual(content, "")
558558

559+
deftestHeadRead(self):
560+
# Test that we don't try to read the response of a HEAD request
561+
# since httplib blocks response.read() for HEAD requests.
562+
uri="http://www.google.com"
563+
(response, content) =self.http.request(uri, "HEAD")
564+
self.assertEqual(response.status, 200)
565+
self.assertEqual(content, "")
566+
559567
deftestGetGZip(self):
560568
# Test that we support gzip compression
561569
uri=urlparse.urljoin(base, "gzip/final-destination.txt")

0 commit comments

Comments
(0)