mirror of
https://github.com/zhigang1992/mitmproxy.git
synced 2026-04-24 04:14:57 +08:00
Sync
This commit is contained in:
36
mitmproxy/addons/intercept.py
Normal file
36
mitmproxy/addons/intercept.py
Normal 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)
|
||||
0
test/mitmproxy/addons/test_intercept.py
Normal file
0
test/mitmproxy/addons/test_intercept.py
Normal file
Reference in New Issue
Block a user