aboutsummaryrefslogtreecommitdiffstats
path: root/examples/modify_response_body.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-02-18 09:19:05 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-02-18 09:27:08 +1300
commit92597f82ea8e4747ce1836ecd5eb2479486e8647 (patch)
tree2aa391b558d92c0122a16c155d3375d31221cde4 /examples/modify_response_body.py
parent49464de1cb159361c16a232b3d8c267b36e95483 (diff)
downloadmitmproxy-92597f82ea8e4747ce1836ecd5eb2479486e8647.tar.gz
mitmproxy-92597f82ea8e4747ce1836ecd5eb2479486e8647.tar.bz2
mitmproxy-92597f82ea8e4747ce1836ecd5eb2479486e8647.zip
Docs and examples to top level
Diffstat (limited to 'examples/modify_response_body.py')
-rw-r--r--examples/modify_response_body.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/examples/modify_response_body.py b/examples/modify_response_body.py
new file mode 100644
index 00000000..88f69e15
--- /dev/null
+++ b/examples/modify_response_body.py
@@ -0,0 +1,18 @@
+# Usage: mitmdump -s "modify_response_body.py mitmproxy bananas"
+# (this script works best with --anticache)
+from mitmproxy.models import decoded
+
+
+def start(context, argv):
+ if len(argv) != 3:
+ raise ValueError('Usage: -s "modify-response-body.py old new"')
+ # You may want to use Python's argparse for more sophisticated argument
+ # parsing.
+ context.old, context.new = argv[1], argv[2]
+
+
+def response(context, flow):
+ with decoded(flow.response): # automatically decode gzipped responses.
+ flow.response.content = flow.response.content.replace(
+ context.old,
+ context.new)