From 3c1ced2b17bbd586332110d5242079bca5cbbe27 Mon Sep 17 00:00:00 2001 From: naivekun Date: Fri, 28 Feb 2020 19:15:42 +0800 Subject: [PATCH] fix #3833 --- mitmproxy/net/http/headers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mitmproxy/net/http/headers.py b/mitmproxy/net/http/headers.py index 8a58cbbc2..baed7e06b 100644 --- a/mitmproxy/net/http/headers.py +++ b/mitmproxy/net/http/headers.py @@ -162,8 +162,12 @@ class Headers(multidict.MultiDict): pattern = re.compile(pattern, flags) replacements = 0 flag_count = count > 0 + count_reached = False fields = [] for name, value in self.fields: + if count_reached: + fields.append((name, value)) + continue line, n = pattern.subn(repl, name + b": " + value, count=count) try: name, value = line.split(b": ", 1) @@ -173,10 +177,12 @@ class Headers(multidict.MultiDict): pass else: replacements += n + fields.append((name, value)) if flag_count: count -= n if count == 0: - break + count_reached = True + continue fields.append((name, value)) self.fields = tuple(fields) return replacements