From 92597f82ea8e4747ce1836ecd5eb2479486e8647 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 18 Feb 2016 09:19:05 +1300 Subject: Docs and examples to top level --- examples/modify_response_body.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/modify_response_body.py (limited to 'examples/modify_response_body.py') 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) -- cgit v1.2.3