From 5327756377d239f059e84de4063cfcaa592fdb3d Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 26 Apr 2017 11:45:15 +1200 Subject: Addons and addon testing - Fix some loading sequence bugs affecting command-line script invocation - Allow addons to over-ride existing options (with a warning). We need this for reloading. - Convert har_dump to new-style arguments, fix and re-instate its test suite. - Covnert miscelaneous other exmples to new-style args. --- examples/simple/filter_flows.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'examples/simple') diff --git a/examples/simple/filter_flows.py b/examples/simple/filter_flows.py index 896fa54a..fd49425a 100644 --- a/examples/simple/filter_flows.py +++ b/examples/simple/filter_flows.py @@ -1,15 +1,21 @@ """ This scripts demonstrates how to use mitmproxy's filter pattern in scripts. -Usage: - mitmdump -s "flowfilter.py FILTER" """ -import sys from mitmproxy import flowfilter +from mitmproxy import ctx class Filter: - def __init__(self, spec): - self.filter = flowfilter.parse(spec) + def __init__(self): + self.filter = None + + def configure(self, updated): + self.filter = flowfilter.parse(ctx.options.flowfilter) + + def load(self, l): + l.add_option( + "flowfilter", str, "", "Check that flow matches filter." + ) def response(self, flow): if flowfilter.match(self.filter, flow): @@ -17,4 +23,4 @@ class Filter: print(flow) -addons = [Filter(sys.argv[1])] +addons = [Filter()] -- cgit v1.2.3