Fixes issue 104.
diff --git a/python2/httplib2/__init__.py b/python2/httplib2/__init__.py
index 05cb5cf..81e9f93 100644
--- a/python2/httplib2/__init__.py
+++ b/python2/httplib2/__init__.py
@@ -1060,7 +1060,7 @@
conn = self.connections[conn_key] = connection_type(authority, timeout=self.timeout, proxy_info=self.proxy_info)
conn.set_debuglevel(debuglevel)
- if method in ["GET", "HEAD"] and 'range' not in headers and 'accept-encoding' not in headers:
+ if 'range' not in headers and 'accept-encoding' not in headers:
headers['accept-encoding'] = 'gzip, deflate'
info = email.Message.Message()
diff --git a/python2/httplib2test.py b/python2/httplib2test.py
index 1c5c49f..3dcfe03 100755
--- a/python2/httplib2test.py
+++ b/python2/httplib2test.py
@@ -703,6 +703,13 @@
self.assertEqual(int(response['content-length']), len("This is the final destination.\n"))
self.assertEqual(content, "This is the final destination.\n")
+ def testPostAndGZipResponse(self):
+ uri = urlparse.urljoin(base, "gzip/post.cgi")
+ (response, content) = self.http.request(uri, "POST", body=" ")
+ self.assertEqual(response.status, 200)
+ self.assertFalse(response.has_key('content-encoding'))
+ self.assertTrue(response.has_key('-content-encoding'))
+
def testGetGZipFailure(self):
# Test that we raise a good exception when the gzip fails
self.http.force_exception_to_status_code = False
diff --git a/python3/httplib2/__init__.py b/python3/httplib2/__init__.py
index 02be175..1f7096d 100644
--- a/python3/httplib2/__init__.py
+++ b/python3/httplib2/__init__.py
@@ -1040,7 +1040,7 @@
conn = self.connections[conn_key] = connection_type(authority, timeout=self.timeout, proxy_info=self.proxy_info)
conn.set_debuglevel(debuglevel)
- if method in ["GET", "HEAD"] and 'range' not in headers and 'accept-encoding' not in headers:
+ if 'range' not in headers and 'accept-encoding' not in headers:
headers['accept-encoding'] = 'gzip, deflate'
info = email.message.Message()
diff --git a/python3/httplib2test.py b/python3/httplib2test.py
index 86569ce..ebaf416 100755
--- a/python3/httplib2test.py
+++ b/python3/httplib2test.py
@@ -699,6 +699,13 @@
self.assertEqual(int(response['content-length']), len(b"This is the final destination.\n"))
self.assertEqual(content, b"This is the final destination.\n")
+ def testPostAndGZipResponse(self):
+ uri = urllib.parse.urljoin(base, "gzip/post.cgi")
+ (response, content) = self.http.request(uri, "POST", body=" ")
+ self.assertEqual(response.status, 200)
+ self.assertFalse('content-encoding' in response)
+ self.assertTrue('-content-encoding' in response)
+
def testGetGZipFailure(self):
# Test that we raise a good exception when the gzip fails
self.http.force_exception_to_status_code = False
diff --git a/test/gzip/post.cgi b/test/gzip/post.cgi
new file mode 100755
index 0000000..97d06d1
--- /dev/null
+++ b/test/gzip/post.cgi
@@ -0,0 +1,12 @@
+#!/usr/bin/env python
+import zlib
+import os
+from StringIO import StringIO
+
+# Always returns a gzipped response body
+print "Status: 200 Ok"
+print ""
+
+print(zlib.compress('This is a compressed string'))
+
+