From 9c24401b187fa2915d8b6cc424fc25f5e51369c8 Mon Sep 17 00:00:00 2001 From: Stephen Altamirano Date: Thu, 21 Jul 2011 22:09:48 -0700 Subject: Removes last_encoding attribute from Response. Prompts for encoding on identity responses --- libmproxy/console.py | 38 +++++++++++++++++++++++++++----------- libmproxy/proxy.py | 1 - 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/libmproxy/console.py b/libmproxy/console.py index 3017669e..3e5ece1d 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -533,23 +533,39 @@ class ConnectionView(WWrap): elif key == "z": if self.state.view_flow_mode == VIEW_FLOW_RESPONSE: conn = self.flow.response - e = conn.headers["content-encoding"] - if e: - if conn.last_encoding: - conn.content = encoding.encode( - conn.last_encoding, - encoding.decode(e[0], conn.content) - ) - conn.last_encoding, conn.headers["content-encoding"] = e[0], [conn.last_encoding] - else: - conn.last_encoding = "identity" - self.master.refresh_connection(self.flow) + e = conn.headers["content-encoding"] or ["identity"] + if e[0] != "identity": + conn.content = encoding.decode(e[0], conn.content) + conn.headers["content-encoding"] = ["identity"] + else: + self.master.prompt_onekey( + "Select encoding: ", + ( + ("gzip", "z"), + ("deflate", "d"), + ), + self.encode_response_callback + ) + self.master.refresh_connection(self.flow) return key def run_script(self, path): if path: self.master._runscript(self.flow, path) + def encode_response_callback(self, key): + conn = self.flow.response + encoding_map = { + "z": "gzip", + "d": "deflate", + } + conn.content = encoding.encode( + encoding_map[key], + conn.content + ) + conn.headers["content-encoding"] = [encoding_map[key]] + self.master.refresh_connection(self.flow) + class _PathCompleter: def __init__(self, _testing=False): diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index abaad255..a7cc31e8 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -290,7 +290,6 @@ class Response(controller.Msg): self.timestamp = timestamp or utils.timestamp() controller.Msg.__init__(self) self.replay = False - self.last_encoding = None def _refresh_cookie(self, c, delta): """ -- cgit v1.2.3