diff options
author | Maximilian Hils <git@maximilianhils.com> | 2016-04-02 14:38:33 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2016-04-02 14:38:33 +0200 |
commit | 806aa0f41c7816b2859a6961939ed19499b73fe7 (patch) | |
tree | 069ce4a304fe3fab07def4a5daa3068c0140f2d8 /netlib/http/request.py | |
parent | 4ee8808b44c5a3377ac2c1dfc4ba5fb10d559ef5 (diff) | |
download | mitmproxy-806aa0f41c7816b2859a6961939ed19499b73fe7.tar.gz mitmproxy-806aa0f41c7816b2859a6961939ed19499b73fe7.tar.bz2 mitmproxy-806aa0f41c7816b2859a6961939ed19499b73fe7.zip |
improve .replace() and move it into netlib
Diffstat (limited to 'netlib/http/request.py')
-rw-r--r-- | netlib/http/request.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/netlib/http/request.py b/netlib/http/request.py index 5bd2547e..07a11969 100644 --- a/netlib/http/request.py +++ b/netlib/http/request.py @@ -54,6 +54,23 @@ class Request(Message): self.method, hostport, path ) + def replace(self, pattern, repl, flags=0): + """ + Replaces a regular expression pattern with repl in the headers, the + request path and the body of the request. Encoded content will be + decoded before replacement, and re-encoded afterwards. + + Returns: + The number of replacements made. + """ + # TODO: Proper distinction between text and bytes. + c = super(Request, self).replace(pattern, repl, flags) + self.path, pc = utils.safe_subn( + pattern, repl, self.path, flags=flags + ) + c += pc + return c + @property def first_line_format(self): """ |