mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-01 07:49:10 +00:00
Merge pull request #1137 from Kriechi/h2-header-encoding
disable http2 header encoding, use bytes everywhere
This commit is contained in:
commit
518cc78454
@ -91,14 +91,14 @@ class Http2Layer(Layer):
|
|||||||
self.mode = mode
|
self.mode = mode
|
||||||
self.streams = dict()
|
self.streams = dict()
|
||||||
self.server_to_client_stream_ids = dict([(0, 0)])
|
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,
|
# make sure that we only pass actual SSL.Connection objects in here,
|
||||||
# because otherwise ssl_read_select fails!
|
# because otherwise ssl_read_select fails!
|
||||||
self.active_conns = [self.client_conn.connection]
|
self.active_conns = [self.client_conn.connection]
|
||||||
|
|
||||||
def _initiate_server_conn(self):
|
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.h2.initiate_connection()
|
||||||
self.server_conn.send(self.server_conn.h2.data_to_send())
|
self.server_conn.send(self.server_conn.h2.data_to_send())
|
||||||
self.active_conns.append(self.server_conn.connection)
|
self.active_conns.append(self.server_conn.connection)
|
||||||
@ -131,12 +131,12 @@ class Http2Layer(Layer):
|
|||||||
eid = event.stream_id
|
eid = event.stream_id
|
||||||
|
|
||||||
if isinstance(event, h2.events.RequestReceived):
|
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] = Http2SingleStreamLayer(self, eid, headers)
|
||||||
self.streams[eid].timestamp_start = time.time()
|
self.streams[eid].timestamp_start = time.time()
|
||||||
self.streams[eid].start()
|
self.streams[eid].start()
|
||||||
elif isinstance(event, h2.events.ResponseReceived):
|
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].queued_data_length = 0
|
||||||
self.streams[eid].timestamp_start = time.time()
|
self.streams[eid].timestamp_start = time.time()
|
||||||
self.streams[eid].response_headers = headers
|
self.streams[eid].response_headers = headers
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
|
||||||
from __future__ import (absolute_import, print_function, division)
|
from __future__ import (absolute_import, print_function, division)
|
||||||
|
|
||||||
import OpenSSL
|
import OpenSSL
|
||||||
@ -36,7 +38,7 @@ class _Http2ServerBase(netlib_tservers.ServerTestBase):
|
|||||||
class handler(netlib.tcp.BaseHandler):
|
class handler(netlib.tcp.BaseHandler):
|
||||||
|
|
||||||
def handle(self):
|
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)
|
preamble = self.rfile.read(24)
|
||||||
h2_conn.initiate_connection()
|
h2_conn.initiate_connection()
|
||||||
@ -122,7 +124,7 @@ class _Http2TestBase(object):
|
|||||||
|
|
||||||
client.convert_to_ssl(alpn_protos=[b'h2'])
|
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()
|
h2_conn.initiate_connection()
|
||||||
client.wfile.write(h2_conn.data_to_send())
|
client.wfile.write(h2_conn.data_to_send())
|
||||||
client.wfile.flush()
|
client.wfile.flush()
|
||||||
@ -163,6 +165,7 @@ class TestSimple(_Http2TestBase, _Http2ServerBase):
|
|||||||
h2_conn.send_headers(1, [
|
h2_conn.send_headers(1, [
|
||||||
(':status', '200'),
|
(':status', '200'),
|
||||||
('foo', 'bar'),
|
('foo', 'bar'),
|
||||||
|
('föo', 'bär'),
|
||||||
])
|
])
|
||||||
h2_conn.send_data(1, b'foobar')
|
h2_conn.send_data(1, b'foobar')
|
||||||
h2_conn.end_stream(1)
|
h2_conn.end_stream(1)
|
||||||
@ -201,6 +204,7 @@ class TestSimple(_Http2TestBase, _Http2ServerBase):
|
|||||||
assert len(self.master.state.flows) == 1
|
assert len(self.master.state.flows) == 1
|
||||||
assert self.master.state.flows[0].response.status_code == 200
|
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['foo'] == 'bar'
|
||||||
|
assert self.master.state.flows[0].response.headers['föo'] == 'bär'
|
||||||
assert self.master.state.flows[0].response.body == b'foobar'
|
assert self.master.state.flows[0].response.body == b'foobar'
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user