diff options
-rw-r--r-- | mitmproxy/addons/intercept.py | 36 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_intercept.py | 0 |
2 files changed, 36 insertions, 0 deletions
diff --git a/mitmproxy/addons/intercept.py b/mitmproxy/addons/intercept.py new file mode 100644 index 00000000..20599e19 --- /dev/null +++ b/mitmproxy/addons/intercept.py @@ -0,0 +1,36 @@ +import ctx +from mitmproxy import flowfilter +from mitmproxy import exceptions + + +class Intercept: + def __init__(self): + self.filt = None + + def configure(self, opts, updated): + if "intercept" in updated: + if not opts.intercept: + self.filt = None + filt = flowfilter.parse(opts.intercept) + if not filt: + raise exceptions.OptionsError( + "Invalid interception filter: %s" % opts.intercept + ) + + def process_flow(self, f): + if self.filt: + should_intercept = all( + self.filt(f), + not f.request.is_replay, + f.reply.state == "handled" + ) + if should_intercept: + f.intercept(ctx.master) + + # Handlers + + def request(self, f): + self.process_flow(f) + + def response(self, f): + self.process_flow(f) diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/mitmproxy/addons/test_intercept.py |