aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-08-03 16:25:38 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-08-03 16:25:38 +0200
commit13f030ccb5f513746fd2bb24c0a3921c5f91f121 (patch)
tree40ec6d629c15bf3da8126daadce8356acb7275d0
parent8f9395060f5afbb56d6e959b16578b9af372e647 (diff)
downloadmitmproxy-13f030ccb5f513746fd2bb24c0a3921c5f91f121.tar.gz
mitmproxy-13f030ccb5f513746fd2bb24c0a3921c5f91f121.tar.bz2
mitmproxy-13f030ccb5f513746fd2bb24c0a3921c5f91f121.zip
suppress SPDY/HTTP2 announcement headers, fix #277
-rw-r--r--libmproxy/protocol/http.py23
-rw-r--r--libmproxy/utils.py6
-rw-r--r--test/test_utils.py6
3 files changed, 12 insertions, 23 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index aed538ef..8e470b01 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -320,15 +320,13 @@ class HTTPRequest(HTTPMessage):
def _assemble_headers(self):
headers = self.headers.copy()
- utils.del_all(
- headers,
- [
- 'Proxy-Connection',
- 'Keep-Alive',
- 'Connection',
- 'Transfer-Encoding'
- ]
- )
+ for k in ['Proxy-Connection',
+ 'Keep-Alive',
+ 'Connection',
+ 'Transfer-Encoding']:
+ del headers[k]
+ if headers["Upgrade"] == ["h2c"]: # Suppress HTTP2 https://http2.github.io/http2-spec/index.html#discover-http
+ del headers["Upgrade"]
if not 'host' in headers:
headers["Host"] = [utils.hostport(self.scheme,
self.host or self.flow.server_conn.address.host,
@@ -636,9 +634,12 @@ class HTTPResponse(HTTPMessage):
def _assemble_headers(self, preserve_transfer_encoding=False):
headers = self.headers.copy()
- utils.del_all(headers, ['Proxy-Connection'])
+ for k in ['Proxy-Connection',
+ 'Alternate-Protocol',
+ 'Alt-Svc']:
+ del headers[k]
if not preserve_transfer_encoding:
- utils.del_all(headers, ['Transfer-Encoding'])
+ del headers['Transfer-Encoding']
if self.content:
headers["Content-Length"] = [str(len(self.content))]
diff --git a/libmproxy/utils.py b/libmproxy/utils.py
index ca48bdf2..33af035f 100644
--- a/libmproxy/utils.py
+++ b/libmproxy/utils.py
@@ -64,12 +64,6 @@ def urlencode(s):
return urllib.urlencode(s, False)
-def del_all(dict, keys):
- for key in keys:
- if key in dict:
- del dict[key]
-
-
def pretty_size(size):
suffixes = [
("B", 2**10),
diff --git a/test/test_utils.py b/test/test_utils.py
index 11c26dba..d99a146d 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -22,12 +22,6 @@ def test_isXml():
assert utils.isXML(" \n<foo")
-def test_del_all():
- d = dict(a=1, b=2, c=3)
- utils.del_all(d, ["a", "x", "b"])
- assert d.keys() == ["c"]
-
-
def test_clean_hanging_newline():
s = "foo\n"
assert utils.clean_hanging_newline(s) == "foo"