aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy.py
diff options
context:
space:
mode:
authoralts <stephen@evilrobotstuff.com>2011-07-16 02:47:06 -0700
committeralts <stephen@evilrobotstuff.com>2011-07-16 02:47:06 -0700
commit6dc0f105ccabeb10f557dc8baa51d3ce08b3c8ee (patch)
tree977c6339d1562a333b1d2087853248ea5ed32771 /libmproxy/proxy.py
parent94ae720a220da4beaa2fc6111b4cafb60b41d33b (diff)
downloadmitmproxy-6dc0f105ccabeb10f557dc8baa51d3ce08b3c8ee.tar.gz
mitmproxy-6dc0f105ccabeb10f557dc8baa51d3ce08b3c8ee.tar.bz2
mitmproxy-6dc0f105ccabeb10f557dc8baa51d3ce08b3c8ee.zip
Adds support for content encoding, namely gip and deflate
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r--libmproxy/proxy.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py
index fe545335..a7cc31e8 100644
--- a/libmproxy/proxy.py
+++ b/libmproxy/proxy.py
@@ -1,7 +1,7 @@
"""
A simple proxy server implementation, which always reads all of a server
response into memory, performs some transformation, and then writes it back
- to the client.
+ to the client.
Development started from Neil Schemenauer's munchy.py
"""
@@ -9,7 +9,7 @@ import sys, os, string, socket, urlparse, re, select, copy, base64, time, Cookie
from email.utils import parsedate_tz, formatdate, mktime_tz
import shutil, tempfile
import optparse, SocketServer, ssl
-import utils, controller
+import utils, controller, encoding
NAME = "mitmproxy"
@@ -53,7 +53,7 @@ def read_chunked(fp):
if line == '\r\n' or line == '\n':
break
return content
-
+
def read_http_body(rfile, connection, headers, all):
if 'transfer-encoding' in headers:
@@ -156,11 +156,21 @@ class Request(controller.Msg):
def anticomp(self):
"""
- Modifies this request to remove headers that might produce a cached
- response. That is, we remove ETags and If-Modified-Since headers.
+ Modifies this request to remove headers that will compress the
+ resource's data.
"""
self.headers["accept-encoding"] = ["identity"]
+ def constrain_encoding(self):
+ """
+ Limits the permissible Accept-Encoding values, based on what we can
+ decode appropriately.
+ """
+ if self.headers["accept-encoding"]:
+ self.headers["accept-encoding"] = [', '.join([
+ e for e in encoding.ENCODINGS if e in self.headers["accept-encoding"][0]
+ ])]
+
def set_replay(self):
self.client_conn = None
@@ -381,7 +391,6 @@ class Response(controller.Msg):
modifications to make sure interception works properly.
"""
headers = self.headers.copy()
- utils.try_del(headers, 'accept-encoding')
utils.try_del(headers, 'proxy-connection')
utils.try_del(headers, 'connection')
utils.try_del(headers, 'keep-alive')