blob: 9e1a283ebe8d1dbf23275a0225b41ca4f86c9292 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
from mitmproxy import flowfilter
from mitmproxy import exceptions
from mitmproxy import ctx
class Intercept:
def __init__(self):
self.filt = None
def configure(self, updated):
if "intercept" in updated:
if not ctx.options.intercept:
self.filt = None
ctx.options.intercept_active = False
return
self.filt = flowfilter.parse(ctx.options.intercept)
if not self.filt:
raise exceptions.OptionsError(
"Invalid interception filter: %s" % ctx.options.intercept
)
ctx.options.intercept_active = True
def process_flow(self, f):
if self.filt:
should_intercept = all([
self.filt(f),
not f.request.is_replay,
])
if should_intercept and ctx.options.intercept_active:
f.intercept()
# Handlers
def request(self, f):
self.process_flow(f)
def response(self, f):
self.process_flow(f)
|