aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2016-12-13 14:03:00 +0100
committerMaximilian Hils <git@maximilianhils.com>2016-12-13 14:12:18 +0100
commite5b3c8bed364f10dadb1e81da7f99a6f5531d965 (patch)
treed461fa1a4796d6a0d6ddfe2372e2d48d418017e4
parentb39380b00fe324a67c107ac2c4a611cbd71b7839 (diff)
downloadmitmproxy-e5b3c8bed364f10dadb1e81da7f99a6f5531d965.tar.gz
mitmproxy-e5b3c8bed364f10dadb1e81da7f99a6f5531d965.tar.bz2
mitmproxy-e5b3c8bed364f10dadb1e81da7f99a6f5531d965.zip
fix #1850
-rw-r--r--mitmproxy/addons/replace.py31
-rw-r--r--mitmproxy/addons/stickyauth.py30
-rw-r--r--mitmproxy/addons/stickycookie.py17
-rw-r--r--mitmproxy/addons/streamfile.py2
-rw-r--r--test/mitmproxy/addons/test_stickyauth.py3
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)