From 8cc0469ee72592d079750a9d5427853d95a7dbfe Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 2 Aug 2011 20:34:01 +1200 Subject: Tweak encoding behaviour - Don't fail to identity encoding when an unknown encoding is specified. - Don't constrain encodings. I want to try to modify traffic as little as possible by default. - When decoding, delete content-encoding header rather than set it to "identity" - Refuse to decode/encode when there is an existing but unknown content-encoding header. --- libmproxy/encoding.py | 12 ++++++++---- libmproxy/flow.py | 2 -- libmproxy/proxy.py | 7 +++++-- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'libmproxy') diff --git a/libmproxy/encoding.py b/libmproxy/encoding.py index aab4141b..6886fb0b 100644 --- a/libmproxy/encoding.py +++ b/libmproxy/encoding.py @@ -8,21 +8,25 @@ __ALL__ = ["ENCODINGS"] ENCODINGS = set(["identity", "gzip", "deflate"]) -def decode(encoding, content): +def decode(e, content): encoding_map = { "identity": identity, "gzip": decode_gzip, "deflate": decode_deflate, } - return encoding_map.get(encoding, identity)(content) + if e not in encoding_map: + return None + return encoding_map[e](content) -def encode(encoding, content): +def encode(e, content): encoding_map = { "identity": identity, "gzip": encode_gzip, "deflate": encode_deflate, } - return encoding_map.get(encoding, identity)(content) + if e not in encoding_map: + return None + return encoding_map[e](content) def identity(content): """ diff --git a/libmproxy/flow.py b/libmproxy/flow.py index 090c539a..57bcc878 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -588,8 +588,6 @@ class FlowMaster(controller.Master): f.request.anticache() if self.anticomp: f.request.anticomp() - else: - f.request.constrain_encoding() if self.server_playback: pb = self.do_server_playback(f) diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 0c142959..75c5bf8a 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -134,11 +134,14 @@ class HTTPMsg(controller.Msg): Content-Encoding header and changing Content-Encoding header to 'identity'. """ + ce = self.headers["content-encoding"] + if not ce or ce[0] not in encoding.ENCODINGS: + return self.content = encoding.decode( - (self.headers["content-encoding"] or ["identity"])[0], + ce[0], self.content ) - self.headers["content-encoding"] = ["identity"] + del self.headers["content-encoding"] def encode(self, e): """ -- cgit v1.2.3