mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
http2: fix h2 header normalization test (#2080)
This commit is contained in:
parent
99b584ad7d
commit
a505221e1a
@ -597,9 +597,6 @@ class Http2SingleStreamLayer(httpbase._HttpTransmissionLayer, basethread.BaseThr
|
|||||||
def send_response_headers(self, response):
|
def send_response_headers(self, response):
|
||||||
headers = response.headers.copy()
|
headers = response.headers.copy()
|
||||||
headers.insert(0, ":status", str(response.status_code))
|
headers.insert(0, ":status", str(response.status_code))
|
||||||
for forbidden_header in h2.utilities.CONNECTION_HEADERS:
|
|
||||||
if forbidden_header in headers:
|
|
||||||
del headers[forbidden_header]
|
|
||||||
with self.connections[self.client_conn].lock:
|
with self.connections[self.client_conn].lock:
|
||||||
self.connections[self.client_conn].safe_send_headers(
|
self.connections[self.client_conn].safe_send_headers(
|
||||||
self.raise_zombie,
|
self.raise_zombie,
|
||||||
|
@ -271,75 +271,6 @@ class TestSimple(_Http2Test):
|
|||||||
assert response_body_buffer == b'response body'
|
assert response_body_buffer == b'response body'
|
||||||
|
|
||||||
|
|
||||||
@requires_alpn
|
|
||||||
class TestForbiddenHeaders(_Http2Test):
|
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def handle_server_event(cls, event, h2_conn, rfile, wfile):
|
|
||||||
if isinstance(event, h2.events.ConnectionTerminated):
|
|
||||||
return False
|
|
||||||
elif isinstance(event, h2.events.StreamEnded):
|
|
||||||
import warnings
|
|
||||||
with warnings.catch_warnings():
|
|
||||||
# Ignore UnicodeWarning:
|
|
||||||
# h2/utilities.py:64: UnicodeWarning: Unicode equal comparison
|
|
||||||
# failed to convert both arguments to Unicode - interpreting
|
|
||||||
# them as being unequal.
|
|
||||||
# elif header[0] in (b'cookie', u'cookie') and len(header[1]) < 20:
|
|
||||||
|
|
||||||
warnings.simplefilter("ignore")
|
|
||||||
|
|
||||||
h2_conn.config.validate_outbound_headers = False
|
|
||||||
h2_conn.send_headers(event.stream_id, [
|
|
||||||
(':status', '200'),
|
|
||||||
('keep-alive', 'foobar'),
|
|
||||||
])
|
|
||||||
h2_conn.send_data(event.stream_id, b'response body')
|
|
||||||
h2_conn.end_stream(event.stream_id)
|
|
||||||
wfile.write(h2_conn.data_to_send())
|
|
||||||
wfile.flush()
|
|
||||||
return True
|
|
||||||
|
|
||||||
def test_forbidden_headers(self):
|
|
||||||
client, h2_conn = self._setup_connection()
|
|
||||||
|
|
||||||
self._send_request(
|
|
||||||
client.wfile,
|
|
||||||
h2_conn,
|
|
||||||
headers=[
|
|
||||||
(':authority', "127.0.0.1:{}".format(self.server.server.address[1])),
|
|
||||||
(':method', 'GET'),
|
|
||||||
(':scheme', 'https'),
|
|
||||||
(':path', '/'),
|
|
||||||
])
|
|
||||||
|
|
||||||
done = False
|
|
||||||
while not done:
|
|
||||||
try:
|
|
||||||
raw = b''.join(http2.read_raw_frame(client.rfile))
|
|
||||||
events = h2_conn.receive_data(raw)
|
|
||||||
except exceptions.HttpException:
|
|
||||||
print(traceback.format_exc())
|
|
||||||
assert False
|
|
||||||
|
|
||||||
client.wfile.write(h2_conn.data_to_send())
|
|
||||||
client.wfile.flush()
|
|
||||||
|
|
||||||
for event in events:
|
|
||||||
if isinstance(event, h2.events.ResponseReceived):
|
|
||||||
assert 'keep-alive' not in event.headers
|
|
||||||
elif isinstance(event, h2.events.StreamEnded):
|
|
||||||
done = True
|
|
||||||
|
|
||||||
h2_conn.close_connection()
|
|
||||||
client.wfile.write(h2_conn.data_to_send())
|
|
||||||
client.wfile.flush()
|
|
||||||
|
|
||||||
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['keep-alive'] == 'foobar'
|
|
||||||
|
|
||||||
|
|
||||||
@requires_alpn
|
@requires_alpn
|
||||||
class TestRequestWithPriority(_Http2Test):
|
class TestRequestWithPriority(_Http2Test):
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user