Skip to content

Commit

Permalink
better http client
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Sep 2, 2015
1 parent d373ca2 commit ad62bf5
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/netius/clients/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def to_response(cls, map):
return netius.common.HTTPResponse(**map)

@classmethod
def gzip_to_plain(cls, data):
def decode_gzip(cls, data):
return zlib.decompress(data, zlib.MAX_WBITS | 16)

def get(
Expand Down Expand Up @@ -500,7 +500,8 @@ def on_message(connection, parser, message):
headers = parser.get_headers()
data = b"".join(buffer)
encoding = headers.get("Content-Encoding", None)
if encoding == "gzip": data = cls.gzip_to_plain(data)
decoder = getattr(cls, "decode_%s") if encoding else None
if decoder: data = decoder(data)
request["code"] = parser.code
request["status"] = parser.status
request["headers"] = headers
Expand Down

0 comments on commit ad62bf5

Please sign in to comment.