From 76b4c6ba82f9a1d6411710c82c67cf264d3bb1d3 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 15 Jul 2011 15:21:04 +1200 Subject: Introduce an anti-compression command-line argument. This is on by default, which means we avoid compressed content unless the -z flag is specified. --- libmproxy/cmdline.py | 7 +++++++ libmproxy/console.py | 2 ++ libmproxy/dump.py | 2 ++ libmproxy/flow.py | 3 +++ libmproxy/proxy.py | 8 +++++++- test/test_flow.py | 1 + 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libmproxy/cmdline.py b/libmproxy/cmdline.py index df77f9d0..e3e6ef4e 100644 --- a/libmproxy/cmdline.py +++ b/libmproxy/cmdline.py @@ -16,6 +16,7 @@ def get_common_options(options): return dict( anticache = options.anticache, + anticomp = options.anticomp, client_replay = options.client_replay, kill = options.kill, no_server = options.no_server, @@ -108,6 +109,12 @@ def common_options(parser): action="store", dest="wfile", default=None, help="Write flows to file." ) + parser.add_option( + "-z", + action="store_false", dest="anticomp", default=True, + help="Try to convince servers to send us un-compressed data." + ) + group = optparse.OptionGroup(parser, "Client Replay") group.add_option( "-c", diff --git a/libmproxy/console.py b/libmproxy/console.py index 6f7061ed..46aacab6 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -767,6 +767,7 @@ class ConsoleState(flow.State): class Options(object): __slots__ = [ "anticache", + "anticomp", "client_replay", "debug", "keepserving", @@ -846,6 +847,7 @@ class ConsoleMaster(flow.FlowMaster): self.refresh_server_playback = options.refresh_server_playback self.anticache = options.anticache + self.anticomp = options.anticomp self.killextra = options.kill self.rheaders = options.rheaders diff --git a/libmproxy/dump.py b/libmproxy/dump.py index b4621716..c68b747e 100644 --- a/libmproxy/dump.py +++ b/libmproxy/dump.py @@ -7,6 +7,7 @@ class DumpError(Exception): pass class Options(object): __slots__ = [ "anticache", + "anticomp", "client_replay", "keepserving", "kill", @@ -54,6 +55,7 @@ class DumpMaster(flow.FlowMaster): self.outfile = outfile self.o = options self.anticache = options.anticache + self.anticomp = options.anticomp self.refresh_server_playback = options.refresh_server_playback if filtstr: diff --git a/libmproxy/flow.py b/libmproxy/flow.py index d29b8e2d..bd07cfa7 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -453,6 +453,7 @@ class FlowMaster(controller.Master): self.stickyauth_txt = None self.anticache = False + self.anticomp = False self.refresh_server_playback = False def _runscript(self, f, script): @@ -565,6 +566,8 @@ class FlowMaster(controller.Master): self._runscript(f, self.scripts["request"]) if self.anticache: f.request.anticache() + if self.anticomp: + f.request.anticomp() if self.server_playback: pb = self.do_server_playback(f) if not pb: diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 690df9f4..fe545335 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -154,6 +154,13 @@ class Request(controller.Msg): for i in delheaders: del self.headers[i] + def anticomp(self): + """ + Modifies this request to remove headers that might produce a cached + response. That is, we remove ETags and If-Modified-Since headers. + """ + self.headers["accept-encoding"] = ["identity"] + def set_replay(self): self.client_conn = None @@ -244,7 +251,6 @@ class Request(controller.Msg): modifications to make sure interception works properly. """ headers = self.headers.copy() - utils.try_del(headers, 'accept-encoding') utils.try_del(headers, 'proxy-connection') utils.try_del(headers, 'keep-alive') utils.try_del(headers, 'connection') diff --git a/test/test_flow.py b/test/test_flow.py index 6ee4235e..365b6c58 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -422,6 +422,7 @@ class uFlowMaster(libpry.AutoTree): s = flow.State() fm = flow.FlowMaster(None, s) fm.anticache = True + fm.anticomp = True req = tutils.treq() fm.handle_clientconnect(req.client_conn) -- cgit v1.2.3