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