diff options
author | Aldo Cortesi <aldo@corte.si> | 2016-07-23 12:32:03 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-23 12:32:03 +1200 |
commit | 45d24696e0ae15c67e46d6cfe4a06ae52ce19888 (patch) | |
tree | f19954d23ce454dd381a62c29af86dcd9ed5cf77 /examples/filt.py | |
parent | 65c2f302186680c09c4a3f10a098000675ae8507 (diff) | |
parent | dbafe9f87bb7b793ae2d84e01af5d39f034c78d4 (diff) | |
download | mitmproxy-45d24696e0ae15c67e46d6cfe4a06ae52ce19888.tar.gz mitmproxy-45d24696e0ae15c67e46d6cfe4a06ae52ce19888.tar.bz2 mitmproxy-45d24696e0ae15c67e46d6cfe4a06ae52ce19888.zip |
Merge pull request #1410 from cortesi/addons
Keep maturing scripts and addons
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]) |