diff options
-rw-r--r-- | mitmproxy/addons/replace.py | 31 | ||||
-rw-r--r-- | mitmproxy/addons/stickyauth.py | 30 | ||||
-rw-r--r-- | mitmproxy/addons/stickycookie.py | 17 | ||||
-rw-r--r-- | mitmproxy/addons/streamfile.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_stickyauth.py | 3 |
5 files changed, 47 insertions, 36 deletions
diff --git a/mitmproxy/addons/replace.py b/mitmproxy/addons/replace.py index b675b779..09200d5d 100644 --- a/mitmproxy/addons/replace.py +++ b/mitmproxy/addons/replace.py @@ -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: diff --git a/mitmproxy/addons/stickyauth.py b/mitmproxy/addons/stickyauth.py index c0d7893d..1a1d4fc4 100644 --- a/mitmproxy/addons/stickyauth.py +++ b/mitmproxy/addons/stickyauth.py @@ -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] diff --git a/mitmproxy/addons/stickycookie.py b/mitmproxy/addons/stickycookie.py index 293de565..fb1c5072 100644 --- a/mitmproxy/addons/stickycookie.py +++ b/mitmproxy/addons/stickycookie.py @@ -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: diff --git a/mitmproxy/addons/streamfile.py b/mitmproxy/addons/streamfile.py index 2fc61015..5517e9dc 100644 --- a/mitmproxy/addons/streamfile.py +++ b/mitmproxy/addons/streamfile.py @@ -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() diff --git a/test/mitmproxy/addons/test_stickyauth.py b/test/mitmproxy/addons/test_stickyauth.py index 490e9aac..df74f44d 100644 --- a/test/mitmproxy/addons/test_stickyauth.py +++ b/test/mitmproxy/addons/test_stickyauth.py @@ -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) |