Permalink
Browse files

Fixes issue 104.

  • Loading branch information...
jcgregorio committed Feb 14, 2011
1 parent f3ee17b commit d1137c5b87562b5b089997cc1ad6a1422d331097
Showing with 28 additions and 2 deletions.
  1. +1 −1 python2/httplib2/__init__.py
  2. +7 −0 python2/httplib2test.py
  3. +1 −1 python3/httplib2/__init__.py
  4. +7 −0 python3/httplib2test.py
  5. +12 −0 test/gzip/post.cgi
@@ -1060,7 +1060,7 @@ def request(self, uri, method="GET", body=None, headers=None, redirections=DEFAU
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()
View
@@ -703,6 +703,13 @@ def testGetGZip(self):
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
@@ -1040,7 +1040,7 @@ def request(self, uri, method="GET", body=None, headers=None, redirections=DEFAU
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()
View
@@ -699,6 +699,13 @@ def testGetGZip(self):
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
View
@@ -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'))
+
+

0 comments on commit d1137c5

Please sign in to comment.