aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-05-05 09:34:22 +1200
committerAldo Cortesi <aldo@corte.si>2018-05-05 09:34:22 +1200
commitf5dc0aace180aea8ba5eadb84fd49c12e8d4af69 (patch)
treec84c7d912b2aae7e8d20b1129f83abd25d14bd28 /examples
parentd12186a935fa8fbaa1cebc5b5ae79c2bdeb78afe (diff)
downloadmitmproxy-f5dc0aace180aea8ba5eadb84fd49c12e8d4af69.tar.gz
mitmproxy-f5dc0aace180aea8ba5eadb84fd49c12e8d4af69.tar.bz2
mitmproxy-f5dc0aace180aea8ba5eadb84fd49c12e8d4af69.zip
Revamp dup_and_replay example
- Exposes view.add as a command - Copes with cases where a view addon isn't present - Avoids infinite loop caused by replaying replays Fixes #3096
Diffstat (limited to 'examples')
-rw-r--r--examples/complex/dup_and_replay.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/complex/dup_and_replay.py b/examples/complex/dup_and_replay.py
index 2baa1ea6..adcebff3 100644
--- a/examples/complex/dup_and_replay.py
+++ b/examples/complex/dup_and_replay.py
@@ -2,7 +2,13 @@ from mitmproxy import ctx
def request(flow):
- f = flow.copy()
- ctx.master.view.add(f)
- f.request.path = "/changed"
- ctx.master.replay_request(f, block=True)
+ # Avoid an infinite loop by not replaying already replayed requests
+ if flow.request.is_replay:
+ return
+ flow = flow.copy()
+ # Only interactive tools have a view. If we have one, add a duplicate entry
+ # for our flow.
+ if "view" in ctx.master.addons:
+ ctx.master.commands.call("view.add", [flow])
+ flow.request.path = "/changed"
+ ctx.master.commands.call("replay.client", [flow])