diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-02-08 01:06:18 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-02-08 01:06:18 +0100 |
commit | 2654cd87afcba318d2cb6ba716a6e2106f24ccb7 (patch) | |
tree | 7cbc03a8164f304b4d859244d0fb7a96df922650 | |
parent | b0477fd8c9f6b1aa80e7e3ebcbe03a204f3ab2c2 (diff) | |
download | mitmproxy-2654cd87afcba318d2cb6ba716a6e2106f24ccb7.tar.gz mitmproxy-2654cd87afcba318d2cb6ba716a6e2106f24ccb7.tar.bz2 mitmproxy-2654cd87afcba318d2cb6ba716a6e2106f24ccb7.zip |
fix #876
-rw-r--r-- | libmproxy/models/http.py | 10 | ||||
-rw-r--r-- | test/test_flow.py | 5 |
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" |