aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libmproxy/models/http.py10
-rw-r--r--test/test_flow.py5
2 files changed, 11 insertions, 4 deletions
diff --git a/libmproxy/models/http.py b/libmproxy/models/http.py
index 8a0b226d..60fcb92c 100644
--- a/libmproxy/models/http.py
+++ b/libmproxy/models/http.py
@@ -91,10 +91,12 @@ class MessageMixin(stateobject.StateObject):
Returns the number of replacements made.
"""
- with decoded(self):
- self.content, count = utils.safe_subn(
- pattern, repl, self.content, *args, **kwargs
- )
+ count = 0
+ if self.content:
+ with decoded(self):
+ self.content, count = utils.safe_subn(
+ pattern, repl, self.content, *args, **kwargs
+ )
fields = []
for name, value in self.headers.fields:
name, c = utils.safe_subn(pattern, repl, name, *args, **kwargs)
diff --git a/test/test_flow.py b/test/test_flow.py
index b8d1fad3..68316f2a 100644
--- a/test/test_flow.py
+++ b/test/test_flow.py
@@ -463,6 +463,11 @@ class TestFlow(object):
f.response.content = "\xc2foo"
f.replace("foo", u"bar")
+ def test_replace_no_content(self):
+ f = tutils.tflow()
+ f.request.content = CONTENT_MISSING
+ assert f.replace("foo", "bar") == 0
+
def test_replace(self):
f = tutils.tflow(resp=True)
f.request.headers["foo"] = "foo"