From 8eec21d553420c51635701c4b57e2df4ddc41890 Mon Sep 17 00:00:00 2001 From: Miroslav Date: Sat, 10 Feb 2018 20:29:38 +0200 Subject: [PATCH 1/2] Fix reverting of a flow --- mitmproxy/addons/core.py | 1 + mitmproxy/tools/console/consoleaddons.py | 1 + 2 files changed, 2 insertions(+) diff --git a/mitmproxy/addons/core.py b/mitmproxy/addons/core.py index 2b0b2f141..fb46f243a 100644 --- a/mitmproxy/addons/core.py +++ b/mitmproxy/addons/core.py @@ -178,6 +178,7 @@ class Core: for f in flows: p = getattr(f, part, None) if p: + f.backup() current_enc = p.headers.get("content-encoding", "identity") if current_enc == "identity": p.encode("deflate") diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index 5907fe95a..deaf016d1 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -383,6 +383,7 @@ class ConsoleAddon: part in ("response-headers", "response-body", "set-cookies") and flow.response is None ) + flow.backup() if require_dummy_response: flow.response = http.HTTPResponse.make() if part == "cookies": From f21979f6ad4da5d184cc1898d6e139712a91ab0d Mon Sep 17 00:00:00 2001 From: Miroslav Date: Mon, 12 Feb 2018 20:39:53 +0200 Subject: [PATCH 2/2] backup for flow.decode/encode --- mitmproxy/addons/core.py | 2 ++ mitmproxy/tools/console/consoleaddons.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/mitmproxy/addons/core.py b/mitmproxy/addons/core.py index fb46f243a..ca21e1dc3 100644 --- a/mitmproxy/addons/core.py +++ b/mitmproxy/addons/core.py @@ -164,6 +164,7 @@ class Core: for f in flows: p = getattr(f, part, None) if p: + f.backup() p.decode() updated.append(f) ctx.master.addons.trigger("update", updated) @@ -205,6 +206,7 @@ class Core: if p: current_enc = p.headers.get("content-encoding", "identity") if current_enc == "identity": + f.backup() p.encode(enc) updated.append(f) ctx.master.addons.trigger("update", updated) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index deaf016d1..7337473c5 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -379,11 +379,12 @@ class ConsoleAddon: # but for now it is. if not flow: raise exceptions.CommandError("No flow selected.") + flow.backup() + require_dummy_response = ( part in ("response-headers", "response-body", "set-cookies") and flow.response is None ) - flow.backup() if require_dummy_response: flow.response = http.HTTPResponse.make() if part == "cookies":