mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
http2: improve error handling in tests
This commit is contained in:
parent
aaf0bba496
commit
5d0de16f57
@ -1,6 +1,7 @@
|
||||
import codecs
|
||||
|
||||
import hyperframe
|
||||
from ...exceptions import HttpException
|
||||
|
||||
|
||||
def http2_read_raw_frame(rfile):
|
||||
@ -8,7 +9,7 @@ def http2_read_raw_frame(rfile):
|
||||
length = int(codecs.encode(header[:3], 'hex_codec'), 16)
|
||||
|
||||
if length == 4740180:
|
||||
raise ValueError("Length field looks more like HTTP/1.1: %s" % rfile.peek(20))
|
||||
raise HttpException("Length field looks more like HTTP/1.1:\n{}".format(rfile.read(-1)))
|
||||
|
||||
body = rfile.safe_read(length)
|
||||
return [header, body]
|
||||
|
@ -13,6 +13,7 @@ from mitmproxy.cmdline import APP_HOST, APP_PORT
|
||||
|
||||
import netlib
|
||||
from ..netlib import tservers as netlib_tservers
|
||||
from netlib.exceptions import HttpException
|
||||
from netlib.http.http2 import framereader
|
||||
|
||||
from . import tservers
|
||||
@ -50,6 +51,9 @@ class _Http2ServerBase(netlib_tservers.ServerTestBase):
|
||||
try:
|
||||
raw = b''.join(framereader.http2_read_raw_frame(self.rfile))
|
||||
events = h2_conn.receive_data(raw)
|
||||
except HttpException:
|
||||
print(traceback.format_exc())
|
||||
assert False
|
||||
except:
|
||||
break
|
||||
self.wfile.write(h2_conn.data_to_send())
|
||||
@ -60,9 +64,7 @@ class _Http2ServerBase(netlib_tservers.ServerTestBase):
|
||||
if not self.server.handle_server_event(event, h2_conn, self.rfile, self.wfile):
|
||||
done = True
|
||||
break
|
||||
except Exception as e:
|
||||
print(repr(e))
|
||||
print(traceback.format_exc())
|
||||
except:
|
||||
done = True
|
||||
break
|
||||
|
||||
@ -200,9 +202,12 @@ class TestSimple(_Http2TestBase, _Http2ServerBase):
|
||||
done = False
|
||||
while not done:
|
||||
try:
|
||||
events = h2_conn.receive_data(b''.join(framereader.http2_read_raw_frame(client.rfile)))
|
||||
except:
|
||||
break
|
||||
raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
|
||||
events = h2_conn.receive_data(raw)
|
||||
except HttpException:
|
||||
print(traceback.format_exc())
|
||||
assert False
|
||||
|
||||
client.wfile.write(h2_conn.data_to_send())
|
||||
client.wfile.flush()
|
||||
|
||||
@ -270,9 +275,12 @@ class TestWithBodies(_Http2TestBase, _Http2ServerBase):
|
||||
done = False
|
||||
while not done:
|
||||
try:
|
||||
events = h2_conn.receive_data(b''.join(framereader.http2_read_raw_frame(client.rfile)))
|
||||
except:
|
||||
break
|
||||
raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
|
||||
events = h2_conn.receive_data(raw)
|
||||
except HttpException:
|
||||
print(traceback.format_exc())
|
||||
assert False
|
||||
|
||||
client.wfile.write(h2_conn.data_to_send())
|
||||
client.wfile.flush()
|
||||
|
||||
@ -364,6 +372,9 @@ class TestPushPromise(_Http2TestBase, _Http2ServerBase):
|
||||
try:
|
||||
raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
|
||||
events = h2_conn.receive_data(raw)
|
||||
except HttpException:
|
||||
print(traceback.format_exc())
|
||||
assert False
|
||||
except:
|
||||
break
|
||||
client.wfile.write(h2_conn.data_to_send())
|
||||
@ -412,9 +423,12 @@ class TestPushPromise(_Http2TestBase, _Http2ServerBase):
|
||||
responses = 0
|
||||
while not done:
|
||||
try:
|
||||
events = h2_conn.receive_data(b''.join(framereader.http2_read_raw_frame(client.rfile)))
|
||||
except:
|
||||
break
|
||||
raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
|
||||
events = h2_conn.receive_data(raw)
|
||||
except HttpException:
|
||||
print(traceback.format_exc())
|
||||
assert False
|
||||
|
||||
client.wfile.write(h2_conn.data_to_send())
|
||||
client.wfile.flush()
|
||||
|
||||
@ -481,6 +495,9 @@ class TestConnectionLost(_Http2TestBase, _Http2ServerBase):
|
||||
try:
|
||||
raw = b''.join(framereader.http2_read_raw_frame(client.rfile))
|
||||
h2_conn.receive_data(raw)
|
||||
except HttpException:
|
||||
print(traceback.format_exc())
|
||||
assert False
|
||||
except:
|
||||
break
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user