aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/http2/protocol.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2015-09-05 18:15:47 +0200
committerMaximilian Hils <git@maximilianhils.com>2015-09-05 18:15:47 +0200
commit66ee1f465f6c492d5a4ff5659e6f0346fb243d67 (patch)
tree81599af6bf38402059dcf6f387dfcf9b599c375e /netlib/http/http2/protocol.py
parent3718e59308745e4582f4e8061b4ff6113d9dfc74 (diff)
downloadmitmproxy-66ee1f465f6c492d5a4ff5659e6f0346fb243d67.tar.gz
mitmproxy-66ee1f465f6c492d5a4ff5659e6f0346fb243d67.tar.bz2
mitmproxy-66ee1f465f6c492d5a4ff5659e6f0346fb243d67.zip
headers: adjust everything
Diffstat (limited to 'netlib/http/http2/protocol.py')
-rw-r--r--netlib/http/http2/protocol.py44
1 files changed, 20 insertions, 24 deletions
diff --git a/netlib/http/http2/protocol.py b/netlib/http/http2/protocol.py
index b297e0b8..f3254caa 100644
--- a/netlib/http/http2/protocol.py
+++ b/netlib/http/http2/protocol.py
@@ -3,7 +3,7 @@ import itertools
import time
from hpack.hpack import Encoder, Decoder
-from netlib import http, utils, odict
+from netlib import http, utils
from netlib.http import semantics
from . import frame
@@ -85,10 +85,10 @@ class HTTP2Protocol(semantics.ProtocolMixin):
timestamp_end = time.time()
- authority = headers.get_first(':authority', '')
- method = headers.get_first(':method', 'GET')
- scheme = headers.get_first(':scheme', 'https')
- path = headers.get_first(':path', '/')
+ authority = headers.get(':authority', '')
+ method = headers.get(':method', 'GET')
+ scheme = headers.get(':scheme', 'https')
+ path = headers.get(':path', '/')
host = None
port = None
@@ -161,7 +161,7 @@ class HTTP2Protocol(semantics.ProtocolMixin):
response = http.Response(
(2, 0),
- int(headers.get_first(':status')),
+ int(headers.get(':status', 502)),
"",
headers,
body,
@@ -181,16 +181,14 @@ class HTTP2Protocol(semantics.ProtocolMixin):
headers = request.headers.copy()
- if ':authority' not in headers.keys():
- headers.add(':authority', bytes(authority), prepend=True)
- if ':scheme' not in headers.keys():
- headers.add(':scheme', bytes(request.scheme), prepend=True)
- if ':path' not in headers.keys():
- headers.add(':path', bytes(request.path), prepend=True)
- if ':method' not in headers.keys():
- headers.add(':method', bytes(request.method), prepend=True)
-
- headers = headers.items()
+ if ':authority' not in headers:
+ headers.fields.insert(0, (':authority', bytes(authority)))
+ if ':scheme' not in headers:
+ headers.fields.insert(0, (':scheme', bytes(request.scheme)))
+ if ':path' not in headers:
+ headers.fields.insert(0, (':path', bytes(request.path)))
+ if ':method' not in headers:
+ headers.fields.insert(0, (':method', bytes(request.method)))
if hasattr(request, 'stream_id'):
stream_id = request.stream_id
@@ -206,10 +204,8 @@ class HTTP2Protocol(semantics.ProtocolMixin):
headers = response.headers.copy()
- if ':status' not in headers.keys():
- headers.add(':status', bytes(str(response.status_code)), prepend=True)
-
- headers = headers.items()
+ if ':status' not in headers:
+ headers.fields.insert(0, (':status', bytes(str(response.status_code))))
if hasattr(response, 'stream_id'):
stream_id = response.stream_id
@@ -329,7 +325,7 @@ class HTTP2Protocol(semantics.ProtocolMixin):
else:
yield frame.ContinuationFrame, i
- header_block_fragment = self.encoder.encode(headers)
+ header_block_fragment = self.encoder.encode(headers.fields)
chunk_size = self.http2_settings[frame.SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE]
chunks = range(0, len(header_block_fragment), chunk_size)
@@ -402,8 +398,8 @@ class HTTP2Protocol(semantics.ProtocolMixin):
else:
self._handle_unexpected_frame(frm)
- headers = odict.ODictCaseless()
- for header, value in self.decoder.decode(header_block_fragment):
- headers.add(header, value)
+ headers = http.Headers(
+ [[str(k), str(v)] for k, v in self.decoder.decode(header_block_fragment)]
+ )
return stream_id, headers, body