Merge pull request #1137 from Kriechi/h2-header-encoding

disable http2 header encoding, use bytes everywhere
This commit is contained in:
Thomas Kriechbaumer 2016-05-11 23:19:12 -05:00
commit 518cc78454
2 changed files with 10 additions and 6 deletions

View File

@ -91,14 +91,14 @@ class Http2Layer(Layer):
self.mode = mode
self.streams = dict()
self.server_to_client_stream_ids = dict([(0, 0)])
self.client_conn.h2 = SafeH2Connection(self.client_conn, client_side=False)
self.client_conn.h2 = SafeH2Connection(self.client_conn, client_side=False, header_encoding=False)
# make sure that we only pass actual SSL.Connection objects in here,
# because otherwise ssl_read_select fails!
self.active_conns = [self.client_conn.connection]
def _initiate_server_conn(self):
self.server_conn.h2 = SafeH2Connection(self.server_conn, client_side=True)
self.server_conn.h2 = SafeH2Connection(self.server_conn, client_side=True, header_encoding=False)
self.server_conn.h2.initiate_connection()
self.server_conn.send(self.server_conn.h2.data_to_send())
self.active_conns.append(self.server_conn.connection)
@ -131,12 +131,12 @@ class Http2Layer(Layer):
eid = event.stream_id
if isinstance(event, h2.events.RequestReceived):
headers = Headers([[str(k), str(v)] for k, v in event.headers])
headers = Headers([[k, v] for k, v in event.headers])
self.streams[eid] = Http2SingleStreamLayer(self, eid, headers)
self.streams[eid].timestamp_start = time.time()
self.streams[eid].start()
elif isinstance(event, h2.events.ResponseReceived):
headers = Headers([[str(k), str(v)] for k, v in event.headers])
headers = Headers([[k, v] for k, v in event.headers])
self.streams[eid].queued_data_length = 0
self.streams[eid].timestamp_start = time.time()
self.streams[eid].response_headers = headers

View File

@ -1,3 +1,5 @@
# coding=utf-8
from __future__ import (absolute_import, print_function, division)
import OpenSSL
@ -36,7 +38,7 @@ class _Http2ServerBase(netlib_tservers.ServerTestBase):
class handler(netlib.tcp.BaseHandler):
def handle(self):
h2_conn = h2.connection.H2Connection(client_side=False)
h2_conn = h2.connection.H2Connection(client_side=False, header_encoding=False)
preamble = self.rfile.read(24)
h2_conn.initiate_connection()
@ -122,7 +124,7 @@ class _Http2TestBase(object):
client.convert_to_ssl(alpn_protos=[b'h2'])
h2_conn = h2.connection.H2Connection(client_side=True)
h2_conn = h2.connection.H2Connection(client_side=True, header_encoding=False)
h2_conn.initiate_connection()
client.wfile.write(h2_conn.data_to_send())
client.wfile.flush()
@ -163,6 +165,7 @@ class TestSimple(_Http2TestBase, _Http2ServerBase):
h2_conn.send_headers(1, [
(':status', '200'),
('foo', 'bar'),
('föo', 'bär'),
])
h2_conn.send_data(1, b'foobar')
h2_conn.end_stream(1)
@ -201,6 +204,7 @@ class TestSimple(_Http2TestBase, _Http2ServerBase):
assert len(self.master.state.flows) == 1
assert self.master.state.flows[0].response.status_code == 200
assert self.master.state.flows[0].response.headers['foo'] == 'bar'
assert self.master.state.flows[0].response.headers['föo'] == 'bär'
assert self.master.state.flows[0].response.body == b'foobar'