aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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