aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authorStephen Altamirano <stephen@evilrobotstuff.com>2011-07-26 22:03:41 -0700
committerStephen Altamirano <stephen@evilrobotstuff.com>2011-07-26 22:03:41 -0700
commitc1eaa9f74c9cf3edc34ced3ab441aede4d0bed01 (patch)
tree44c90eec8b149207127f452ce8fa61b42378f565 /libmproxy/proxy.py
parente6288e2d0751502eee1a44723a36230c12b821f3 (diff)
downloadmitmproxy-c1eaa9f74c9cf3edc34ced3ab441aede4d0bed01.tar.gz
mitmproxy-c1eaa9f74c9cf3edc34ced3ab441aede4d0bed01.tar.bz2
mitmproxy-c1eaa9f74c9cf3edc34ced3ab441aede4d0bed01.zip
Adds encode and decode methods to Response objects
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py27
1 files changed, 24 insertions, 3 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index 8d2888a4..9f2ed644 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -284,7 +284,7 @@ class Request(controller.Msg):
"""
Replaces a regular expression pattern with repl in both the headers
and the body of the request. Returns the number of replacements
- made.
+ made.
"""
self.content, c = re.subn(pattern, repl, self.content, count, flags)
self.path, pc = re.subn(pattern, repl, self.path, count, flags)
@@ -422,12 +422,33 @@ class Response(controller.Msg):
"""
Replaces a regular expression pattern with repl in both the headers
and the body of the response. Returns the number of replacements
- made.
+ made.
"""
self.content, c = re.subn(pattern, repl, self.content, count, flags)
c += self.headers.replace(pattern, repl, count, flags)
return c
+ def decode(self):
+ """
+ Alters Response object, decoding its content based on the current
+ Content-Encoding header and changing Content-Encoding header to
+ 'identity'.
+ """
+ self.content = encoding.decode(
+ (self.headers["content-encoding"] or ["identity"])[0],
+ self.content
+ )
+ self.headers["content-encoding"] = ["identity"]
+
+ def encode(self, e):
+ """
+ Alters Response object, encoding its content with the specified
+ coding. This method should only be called on Responses with
+ Content-Encoding headers of 'identity'.
+ """
+ self.content = encoding.encode(e, self.content)
+ self.headers["content-encoding"] = [e]
+
class ClientDisconnect(controller.Msg):
def __init__(self, client_conn):
@@ -501,7 +522,7 @@ class Error(controller.Msg):
"""
Replaces a regular expression pattern with repl in both the headers
and the body of the request. Returns the number of replacements
- made.
+ made.
"""
self.msg, c = re.subn(pattern, repl, self.msg, count, flags)
return c