Fixed bug #56
diff --git a/httplib2/__init__.py b/httplib2/__init__.py
index 684e1ce..6c289e8 100755
--- a/httplib2/__init__.py
+++ b/httplib2/__init__.py
@@ -860,7 +860,9 @@
else:
raise
else:
- content = response.read()
+ content = ""
+ if method != "HEAD":
+ content = response.read()
response = Response(response)
if method != "HEAD":
content = _decompressContent(response, content)
diff --git a/httplib2test.py b/httplib2test.py
index b812a53..f882b17 100755
--- a/httplib2test.py
+++ b/httplib2test.py
@@ -187,6 +187,16 @@
(response, content) = self.http.request(uri, method, body=" ")
self.assertEqual(response['x-method'], method)
+ def testHeadRead(self):
+ # Test that we don't try to read the response of a HEAD request
+ # since httplib blocks response.read() for HEAD requests.
+ # Oddly enough this doesn't appear as a problem when doing HEAD requests
+ # against Apache servers.
+ uri = "http://www.google.com/"
+ (response, content) = self.http.request(uri, "HEAD")
+ self.assertEqual(response.status, 200)
+ self.assertEqual(content, "")
+
def testGetNoCache(self):
# Test that can do a GET w/o the cache turned on.
http = httplib2.Http()
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py
index 9bf9136..d660796 100755
--- a/python3/httplib2/__init__.py
+++ b/python3/httplib2/__init__.py
@@ -845,7 +845,9 @@
else:
raise
else:
- content = response.read()
+ content = b""
+ if method != "HEAD":
+ content = response.read()
response = Response(response)
if method != "HEAD":
content = _decompressContent(response, content)
diff --git a/python3/httplib2test.py b/python3/httplib2test.py
index e2bdae3..5b91164 100755
--- a/python3/httplib2test.py
+++ b/python3/httplib2test.py
@@ -185,6 +185,16 @@
(response, content) = self.http.request(uri, method, body=b" ")
self.assertEqual(response['x-method'], method)
+ def testHeadRead(self):
+ # Test that we don't try to read the response of a HEAD request
+ # since httplib blocks response.read() for HEAD requests.
+ # Oddly enough this doesn't appear as a problem when doing HEAD requests
+ # against Apache servers.
+ uri = "http://www.google.com/"
+ (response, content) = self.http.request(uri, "HEAD")
+ self.assertEqual(response.status, 200)
+ self.assertEqual(content, b"")
+
def testGetNoCache(self):
# Test that can do a GET w/o the cache turned on.
http = httplib2.Http()