aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'libmproxy/utils.py')
-rw-r--r--libmproxy/utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/libmproxy/utils.py b/libmproxy/utils.py
index 4d8c7c41..9ac9c0b8 100644
--- a/libmproxy/utils.py
+++ b/libmproxy/utils.py
@@ -279,6 +279,21 @@ class Headers:
ret.append([name, value])
self.lst = ret
+ def replace(self, pattern, repl, count=0, flags=0):
+ """
+ Replaces a regular expression pattern with repl in both header keys
+ and values. Returns the number of replacements made.
+ """
+ nlst, count = [], 0
+ for i in self.lst:
+ k, c = re.subn(pattern, repl, i[0], count, flags)
+ count += c
+ v, c = re.subn(pattern, repl, i[1], count, flags)
+ count += c
+ nlst.append([k, v])
+ self.lst = nlst
+ return count
+
def pretty_size(size):
suffixes = [