aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--netlib/http/http2/protocol.py19
-rw-r--r--netlib/odict.py2
-rw-r--r--test/http/http2/test_protocol.py8
3 files changed, 15 insertions, 14 deletions
diff --git a/netlib/http/http2/protocol.py b/netlib/http/http2/protocol.py
index 1dfdda21..55b5ca76 100644
--- a/netlib/http/http2/protocol.py
+++ b/netlib/http/http2/protocol.py
@@ -2,7 +2,7 @@ from __future__ import (absolute_import, print_function, division)
import itertools
from hpack.hpack import Encoder, Decoder
-from netlib import http, utils
+from netlib import http, utils, odict
from . import frame
@@ -189,7 +189,8 @@ class HTTP2Protocol(object):
def read_response(self, *args):
stream_id, headers, body = self._receive_transmission()
- response = http.Response("HTTP/2", headers[':status'], "", headers, body)
+ status = headers[':status'][0]
+ response = http.Response("HTTP/2", status, "", headers, body)
response.stream_id = stream_id
return response
@@ -197,11 +198,11 @@ class HTTP2Protocol(object):
stream_id, headers, body = self._receive_transmission()
form_in = ""
- method = headers.get(':method', '')
- scheme = headers.get(':scheme', '')
- host = headers.get(':host', '')
+ method = headers.get(':method', [''])[0]
+ scheme = headers.get(':scheme', [''])[0]
+ host = headers.get(':host', [''])[0]
port = '' # TODO: parse port number?
- path = headers.get(':path', '')
+ path = headers.get(':path', [''])[0]
request = http.Request(form_in, method, scheme, host, port, path, "HTTP/2", headers, body)
request.stream_id = stream_id
@@ -233,15 +234,17 @@ class HTTP2Protocol(object):
break
# TODO: implement window update & flow
- headers = {}
+ headers = odict.ODictCaseless()
for header, value in self.decoder.decode(header_block_fragment):
- headers[header] = value
+ headers.add(header, value)
return stream_id, headers, body
def create_response(self, code, stream_id=None, headers=None, body=None):
if headers is None:
headers = []
+ if isinstance(headers, odict.ODict):
+ headers = headers.items()
headers = [(b':status', bytes(str(code)))] + headers
diff --git a/netlib/odict.py b/netlib/odict.py
index ee1e6938..f52acd50 100644
--- a/netlib/odict.py
+++ b/netlib/odict.py
@@ -20,8 +20,6 @@ class ODict(object):
"""
def __init__(self, lst=None):
- if isinstance(lst, ODict):
- lst = lst.items()
self.lst = lst or []
def _kconv(self, s):
diff --git a/test/http/http2/test_protocol.py b/test/http/http2/test_protocol.py
index 34e4ef50..d3040266 100644
--- a/test/http/http2/test_protocol.py
+++ b/test/http/http2/test_protocol.py
@@ -1,6 +1,6 @@
import OpenSSL
-from netlib import tcp
+from netlib import tcp, odict
from netlib.http import http2
from netlib.http.http2.frame import *
from ... import tutils, tservers
@@ -256,7 +256,7 @@ class TestReadResponse(tservers.ServerTestBase):
assert resp.httpversion == "HTTP/2"
assert resp.status_code == "200"
assert resp.msg == ""
- assert resp.headers == {':status': '200', 'etag': 'foobar'}
+ assert resp.headers.lst == [[':status', '200'], ['etag', 'foobar']]
assert resp.body == b'foobar'
@@ -282,7 +282,7 @@ class TestReadEmptyResponse(tservers.ServerTestBase):
assert resp.httpversion == "HTTP/2"
assert resp.status_code == "200"
assert resp.msg == ""
- assert resp.headers == {':status': '200', 'etag': 'foobar'}
+ assert resp.headers.lst == [[':status', '200'], ['etag', 'foobar']]
assert resp.body == b''
@@ -307,7 +307,7 @@ class TestReadRequest(tservers.ServerTestBase):
resp = protocol.read_request()
assert resp.stream_id
- assert resp.headers == {':method': 'GET', ':path': '/', ':scheme': 'https'}
+ assert resp.headers.lst == [[u':method', u'GET'], [u':path', u'/'], [u':scheme', u'https']]
assert resp.body == b'foobar'