diff options
author | arjun23496 <arjun.k018@gmail.com> | 2016-08-29 16:50:14 +0530 |
---|---|---|
committer | arjun23496 <arjun.k018@gmail.com> | 2016-08-29 16:50:14 +0530 |
commit | 99744cc780a5100ac028bbbf43e8a42e1167047e (patch) | |
tree | f79f04daba1a3b2af987a23ec7d6d66c59473c9a /netlib/http/headers.py | |
parent | 70f94c7171cac9659feccfb0f974f72d4bc33a80 (diff) | |
download | mitmproxy-99744cc780a5100ac028bbbf43e8a42e1167047e.tar.gz mitmproxy-99744cc780a5100ac028bbbf43e8a42e1167047e.tar.bz2 mitmproxy-99744cc780a5100ac028bbbf43e8a42e1167047e.zip |
Added replace for request and headers - Fixed missing replace option
Diffstat (limited to 'netlib/http/headers.py')
-rw-r--r-- | netlib/http/headers.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/netlib/http/headers.py b/netlib/http/headers.py index 36e5060c..60a36515 100644 --- a/netlib/http/headers.py +++ b/netlib/http/headers.py @@ -158,7 +158,7 @@ class Headers(multidict.MultiDict): else: return super(Headers, self).items() - def replace(self, pattern, repl, flags=0): + def replace(self, pattern, repl, flags=0, count=0): """ Replaces a regular expression pattern with repl in each "name: value" header line. @@ -175,7 +175,7 @@ class Headers(multidict.MultiDict): fields = [] for name, value in self.fields: - line, n = pattern.subn(repl, name + b": " + value) + line, n = pattern.subn(repl, name + b": " + value, count=count) try: name, value = line.split(b": ", 1) except ValueError: @@ -183,6 +183,7 @@ class Headers(multidict.MultiDict): # There's not much we can do about this, so we just keep the header as-is. pass else: + count -= n replacements += n fields.append((name, value)) self.fields = tuple(fields) |