mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 18:18:25 +00:00
commit
e2c6d7ed0f
@ -16,21 +16,22 @@ class Replace:
|
||||
rex: a regular expression, as bytes.
|
||||
s: the replacement string, as bytes
|
||||
"""
|
||||
lst = []
|
||||
for fpatt, rex, s in options.replacements:
|
||||
flt = flowfilter.parse(fpatt)
|
||||
if not flt:
|
||||
raise exceptions.OptionsError(
|
||||
"Invalid filter pattern: %s" % fpatt
|
||||
)
|
||||
try:
|
||||
re.compile(rex)
|
||||
except re.error as e:
|
||||
raise exceptions.OptionsError(
|
||||
"Invalid regular expression: %s - %s" % (rex, str(e))
|
||||
)
|
||||
lst.append((rex, s, flt))
|
||||
self.lst = lst
|
||||
if "replacements" in updated:
|
||||
lst = []
|
||||
for fpatt, rex, s in options.replacements:
|
||||
flt = flowfilter.parse(fpatt)
|
||||
if not flt:
|
||||
raise exceptions.OptionsError(
|
||||
"Invalid filter pattern: %s" % fpatt
|
||||
)
|
||||
try:
|
||||
re.compile(rex)
|
||||
except re.error as e:
|
||||
raise exceptions.OptionsError(
|
||||
"Invalid regular expression: %s - %s" % (rex, str(e))
|
||||
)
|
||||
lst.append((rex, s, flt))
|
||||
self.lst = lst
|
||||
|
||||
def execute(self, f):
|
||||
for rex, s, flt in self.lst:
|
||||
|
@ -8,18 +8,22 @@ class StickyAuth:
|
||||
self.hosts = {}
|
||||
|
||||
def configure(self, options, updated):
|
||||
if options.stickyauth:
|
||||
flt = flowfilter.parse(options.stickyauth)
|
||||
if not flt:
|
||||
raise exceptions.OptionsError(
|
||||
"stickyauth: invalid filter expression: %s" % options.stickyauth
|
||||
)
|
||||
self.flt = flt
|
||||
if "stickyauth" in updated:
|
||||
if options.stickyauth:
|
||||
flt = flowfilter.parse(options.stickyauth)
|
||||
if not flt:
|
||||
raise exceptions.OptionsError(
|
||||
"stickyauth: invalid filter expression: %s" % options.stickyauth
|
||||
)
|
||||
self.flt = flt
|
||||
else:
|
||||
self.flt = None
|
||||
|
||||
def request(self, flow):
|
||||
host = flow.request.host
|
||||
if "authorization" in flow.request.headers:
|
||||
self.hosts[host] = flow.request.headers["authorization"]
|
||||
elif flowfilter.match(self.flt, flow):
|
||||
if host in self.hosts:
|
||||
flow.request.headers["authorization"] = self.hosts[host]
|
||||
if self.flt:
|
||||
host = flow.request.host
|
||||
if "authorization" in flow.request.headers:
|
||||
self.hosts[host] = flow.request.headers["authorization"]
|
||||
elif flowfilter.match(self.flt, flow):
|
||||
if host in self.hosts:
|
||||
flow.request.headers["authorization"] = self.hosts[host]
|
||||
|
@ -34,13 +34,16 @@ class StickyCookie:
|
||||
self.flt = None
|
||||
|
||||
def configure(self, options, updated):
|
||||
if options.stickycookie:
|
||||
flt = flowfilter.parse(options.stickycookie)
|
||||
if not flt:
|
||||
raise exceptions.OptionsError(
|
||||
"stickycookie: invalid filter expression: %s" % options.stickycookie
|
||||
)
|
||||
self.flt = flt
|
||||
if "stickycookie" in updated:
|
||||
if options.stickycookie:
|
||||
flt = flowfilter.parse(options.stickycookie)
|
||||
if not flt:
|
||||
raise exceptions.OptionsError(
|
||||
"stickycookie: invalid filter expression: %s" % options.stickycookie
|
||||
)
|
||||
self.flt = flt
|
||||
else:
|
||||
self.flt = None
|
||||
|
||||
def response(self, flow):
|
||||
if self.flt:
|
||||
|
@ -29,6 +29,8 @@ class StreamFile:
|
||||
raise exceptions.OptionsError(
|
||||
"Invalid filter specification: %s" % options.filtstr
|
||||
)
|
||||
else:
|
||||
self.filt = None
|
||||
if "streamfile" in updated:
|
||||
if self.stream:
|
||||
self.done()
|
||||
|
@ -15,7 +15,8 @@ def test_configure():
|
||||
|
||||
def test_simple():
|
||||
r = stickyauth.StickyAuth()
|
||||
with taddons.context():
|
||||
with taddons.context() as tctx:
|
||||
tctx.configure(r, stickyauth=".*")
|
||||
f = tflow.tflow(resp=True)
|
||||
f.request.headers["authorization"] = "foo"
|
||||
r.request(f)
|
||||
|
Loading…
Reference in New Issue
Block a user