diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-07-25 15:16:16 -0700 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-07-25 15:16:16 -0700 |
commit | 79ebcb046e8669f80357a6c3046ec76c6adf49be (patch) | |
tree | 441981a16f1be1e620584e4a47f41767ce5585b2 /examples/filt.py | |
parent | 3254595584e1d711e7ae292ad34753a52f7a0fc1 (diff) | |
parent | 56796aeda25dda66621ce78af227ff46049ef811 (diff) | |
download | mitmproxy-79ebcb046e8669f80357a6c3046ec76c6adf49be.tar.gz mitmproxy-79ebcb046e8669f80357a6c3046ec76c6adf49be.tar.bz2 mitmproxy-79ebcb046e8669f80357a6c3046ec76c6adf49be.zip |
Merge remote-tracking branch 'origin/master' into flow_editing_v2
Diffstat (limited to 'examples/filt.py')
-rw-r--r-- | examples/filt.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/examples/filt.py b/examples/filt.py index 21744edd..9ccf9fa1 100644 --- a/examples/filt.py +++ b/examples/filt.py @@ -1,18 +1,20 @@ -# This scripts demonstrates how to use mitmproxy's filter pattern in inline scripts. +# This scripts demonstrates how to use mitmproxy's filter pattern in scripts. # Usage: mitmdump -s "filt.py FILTER" import sys from mitmproxy import filt -state = {} + +class Filter: + def __init__(self, spec): + self.filter = filt.parse(spec) + + def response(self, flow): + if flow.match(self.filter): + print("Flow matches filter:") + print(flow) def start(): if len(sys.argv) != 2: raise ValueError("Usage: -s 'filt.py FILTER'") - state["filter"] = filt.parse(sys.argv[1]) - - -def response(flow): - if flow.match(state["filter"]): - print("Flow matches filter:") - print(flow) + return Filter(sys.argv[1]) |