This commit is contained in:
Aldo Cortesi
2016-10-29 12:35:10 +13:00
parent 005c22445b
commit 71d2636594
2 changed files with 36 additions and 0 deletions

View File

@@ -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)

View File