diff options
author | Maximilian Hils <git@maximilianhils.com> | 2014-12-01 02:28:03 +0100 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2014-12-01 02:28:03 +0100 |
commit | 992536c2bc0afa5da81e82cfcd8953663559ff59 (patch) | |
tree | b42f07b10231cec0251fd4470c650d73a00cba82 | |
parent | 56f1278d1a0233620289d2fa4173449ed108a73e (diff) | |
download | mitmproxy-992536c2bc0afa5da81e82cfcd8953663559ff59.tar.gz mitmproxy-992536c2bc0afa5da81e82cfcd8953663559ff59.tar.bz2 mitmproxy-992536c2bc0afa5da81e82cfcd8953663559ff59.zip |
make header processing configurable by inline scripts, refs #340
-rw-r--r-- | libmproxy/protocol/http.py | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 386a3666..89af85b0 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -419,17 +419,19 @@ class HTTPRequest(HTTPMessage): raise http.HttpError(400, "Invalid request form") return request_line + # This list is adopted legacy code. + # We probably don't need to strip off keep-alive. + _headers_to_strip_off = ['Proxy-Connection', + 'Keep-Alive', + 'Connection', + 'Transfer-Encoding', + 'Upgrade'] + def _assemble_headers(self): headers = self.headers.copy() - for k in ['Proxy-Connection', - 'Keep-Alive', - 'Connection', - 'Transfer-Encoding']: + for k in self._headers_to_strip_off: 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 and self.scheme and self.host and self.port: + if 'host' not in headers and self.scheme and self.host and self.port: headers["Host"] = [utils.hostport(self.scheme, self.host, self.port)] @@ -750,11 +752,13 @@ class HTTPResponse(HTTPMessage): return 'HTTP/%s.%s %s %s' % \ (self.httpversion[0], self.httpversion[1], self.code, self.msg) + _headers_to_strip_off = ['Proxy-Connection', + 'Alternate-Protocol', + 'Alt-Svc'] + def _assemble_headers(self, preserve_transfer_encoding=False): headers = self.headers.copy() - for k in ['Proxy-Connection', - 'Alternate-Protocol', - 'Alt-Svc']: + for k in self._headers_to_strip_off: del headers[k] if not preserve_transfer_encoding: del headers['Transfer-Encoding'] |