From dd2e0d1df3eeb934c291dd6197f722e419dd3e43 Mon Sep 17 00:00:00 2001 From: arjun23496 Date: Wed, 31 Aug 2016 16:11:59 +0530 Subject: [PATCH] minor bug fix header replace --- netlib/http/headers.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/netlib/http/headers.py b/netlib/http/headers.py index f4cf8b7b7..5f724f6df 100644 --- a/netlib/http/headers.py +++ b/netlib/http/headers.py @@ -172,6 +172,7 @@ class Headers(multidict.MultiDict): repl = strutils.escaped_str_to_bytes(repl) pattern = re.compile(pattern, flags) replacements = 0 + flag_count = count > 0 fields = [] for name, value in self.fields: @@ -183,10 +184,13 @@ 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 - if count == 0: - break; + + if flag_count: + count -= n + if count == 0: + break; + fields.append((name, value)) self.fields = tuple(fields) return replacements