aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-02-27 14:47:50 +0100
committerMaximilian Hils <git@maximilianhils.com>2015-02-27 14:47:50 +0100
commit8d975e80ffbbf2af5f1d097a21dbb33e17acc6a1 (patch)
tree23989c9af0e84e06fc844b6029ec8087014c5387 /examples
parent595bde2202880971907096e4eeddb2b298c02d07 (diff)
parent5916767e036c6c7a816aa964bcd2b2721c7316bb (diff)
downloadmitmproxy-8d975e80ffbbf2af5f1d097a21dbb33e17acc6a1.tar.gz
mitmproxy-8d975e80ffbbf2af5f1d097a21dbb33e17acc6a1.tar.bz2
mitmproxy-8d975e80ffbbf2af5f1d097a21dbb33e17acc6a1.zip
Merge remote-tracking branch 'sakurai/feature/issue319'
Diffstat (limited to 'examples')
-rw-r--r--examples/stream_modify.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/examples/stream_modify.py b/examples/stream_modify.py
new file mode 100644
index 00000000..a28d95c7
--- /dev/null
+++ b/examples/stream_modify.py
@@ -0,0 +1,19 @@
+"""
+This inline script won't work with --stream SIZE command line option.
+
+That's because flow.response.stream will be overwritten to True if the
+command line option exists.
+"""
+
+def modify(chunks):
+ """
+ chunks is a generator that can be used to iterate over all chunks.
+ Each chunk is a (prefix, content, suffix) tuple.
+ For example, in the case of chunked transfer encoding: ("3\r\n","foo","\r\n")
+ """
+ for prefix, content, suffix in chunks:
+ yield prefix, content.replace("foo","bar"), suffix
+
+def responseheaders(ctx, flow):
+ flow.response.stream = modify
+ flow.response.stream_large_bodies = 1024 # = 1KB