Skip to content

Commit

Permalink
fix deflate in pyparser too.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitc committed Aug 30, 2013
1 parent d2b3925 commit 6683814
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion http_parser/pyparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def __init__(self, kind=2, decompress=False):
self.__on_message_complete = False

self.__decompress_obj = None
self.__decompress_first_try = True

def get_version(self):
return self._version
Expand Down Expand Up @@ -384,6 +385,7 @@ def _parse_headers(self, data):
if self.decompress:
if encoding == "gzip":
self.__decompress_obj = zlib.decompressobj(16+zlib.MAX_WBITS)
self.__decompress_first_try = False
elif encoding == "deflate":
self.__decompress_obj = zlib.decompressobj()

Expand All @@ -399,7 +401,16 @@ def _parse_body(self):

# maybe decompress
if self.__decompress_obj is not None:
body_part = self.__decompress_obj.decompress(body_part)
if not self.__decompress_first_try:
body_part = self.__decompress_obj.decompress(body_part)
else:
try:
body_part = self.__decompress_obj.decompress(body_part)
except zlib.error:
res.decompressobj = zlib.decompressobj(-zlib.MAX_WBITS)
body_part = self.__decompress_obj.decompress(body_part)
self.__decompress_first_try = False


self._partial_body = True
self._body.append(body_part)
Expand Down

0 comments on commit 6683814

Please sign in to comment.