aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-04-12 03:47:58 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-04-12 03:47:58 +0200
commitc0a318566ae0fb5a264bfaa130f3ff3a09ea5bf5 (patch)
tree276583c71b7bb0425bad1953ebae4a7cc9c34a5f
parent923503260ed48510da63e4dd1d6b36b4b859b110 (diff)
downloadmitmproxy-c0a318566ae0fb5a264bfaa130f3ff3a09ea5bf5.tar.gz
mitmproxy-c0a318566ae0fb5a264bfaa130f3ff3a09ea5bf5.tar.bz2
mitmproxy-c0a318566ae0fb5a264bfaa130f3ff3a09ea5bf5.zip
add flowwriter example
-rw-r--r--examples/flowwriter.py17
-rw-r--r--test/test_examples.py2
2 files changed, 18 insertions, 1 deletions
diff --git a/examples/flowwriter.py b/examples/flowwriter.py
new file mode 100644
index 00000000..2c253fbb
--- /dev/null
+++ b/examples/flowwriter.py
@@ -0,0 +1,17 @@
+from libmproxy.flow import FlowWriter
+import random
+import sys
+
+def start(context, argv):
+ if len(argv) != 2:
+ raise ValueError('Usage: -s "flowriter.py filename"')
+
+ if argv[1] == "-":
+ f = sys.stdout
+ else:
+ f = open(argv[1], "wb")
+ context.flow_writer = FlowWriter(f)
+
+def response(context, flow):
+ if random.choice([True, False]):
+ context.flow_writer.add(flow) \ No newline at end of file
diff --git a/test/test_examples.py b/test/test_examples.py
index daf4b902..fd901b5d 100644
--- a/test/test_examples.py
+++ b/test/test_examples.py
@@ -11,7 +11,7 @@ def test_load_scripts():
tmaster = tservers.TestMaster(config.ProxyConfig())
for f in scripts:
- if "har_extractor" in f:
+ if "har_extractor" in f or "flowwriter" in f:
f += " -"
if "iframe_injector" in f:
f += " foo" # one argument required