aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/encoding.py
diff options
context:
space:
mode:
authorJim Shaver <dcypherd@gmail.com>2015-05-31 01:21:44 -0400
committerJim Shaver <dcypherd@gmail.com>2015-05-31 01:21:44 -0400
commitb51363b3ca43f6572acb673186e6ae78a1f48434 (patch)
treea7488b32871c142141a813dc6ff2ede172672c31 /libmproxy/encoding.py
parent4fe2c069cca07aadf983f54e18dac4de492d5d69 (diff)
parent06fba18106a8f759ec6f08453e86772a170c653b (diff)
downloadmitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.tar.gz
mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.tar.bz2
mitmproxy-b51363b3ca43f6572acb673186e6ae78a1f48434.zip
Merge remote-tracking branch 'upstream/master' into print-bracket-fix
Conflicts: examples/har_extractor.py examples/nonblocking.py examples/read_dumpfile libmproxy/web/app.py
Diffstat (limited to 'libmproxy/encoding.py')
-rw-r--r--libmproxy/encoding.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/libmproxy/encoding.py b/libmproxy/encoding.py
index 0fd90870..f107eb5f 100644
--- a/libmproxy/encoding.py
+++ b/libmproxy/encoding.py
@@ -3,12 +3,14 @@
"""
from __future__ import absolute_import
import cStringIO
-import gzip, zlib
+import gzip
+import zlib
__ALL__ = ["ENCODINGS"]
ENCODINGS = set(["identity", "gzip", "deflate"])
+
def decode(e, content):
encoding_map = {
"identity": identity,
@@ -19,6 +21,7 @@ def decode(e, content):
return None
return encoding_map[e](content)
+
def encode(e, content):
encoding_map = {
"identity": identity,
@@ -29,6 +32,7 @@ def encode(e, content):
return None
return encoding_map[e](content)
+
def identity(content):
"""
Returns content unchanged. Identity is the default value of
@@ -36,6 +40,7 @@ def identity(content):
"""
return content
+
def decode_gzip(content):
gfile = gzip.GzipFile(fileobj=cStringIO.StringIO(content))
try:
@@ -43,6 +48,7 @@ def decode_gzip(content):
except (IOError, EOFError):
return None
+
def encode_gzip(content):
s = cStringIO.StringIO()
gf = gzip.GzipFile(fileobj=s, mode='wb')
@@ -50,6 +56,7 @@ def encode_gzip(content):
gf.close()
return s.getvalue()
+
def decode_deflate(content):
"""
Returns decompressed data for DEFLATE. Some servers may respond with
@@ -67,6 +74,7 @@ def decode_deflate(content):
except zlib.error:
return None
+
def encode_deflate(content):
"""
Returns compressed content, always including zlib header and checksum.