This commit is contained in:
Maximilian Hils 2020-11-17 19:11:28 +01:00
parent c3ccc25cfb
commit 1490d665fe
4 changed files with 26 additions and 8 deletions

View File

@ -181,19 +181,20 @@ class Dumper:
replay_str = "" replay_str = ""
replay = "" replay = ""
code = flow.response.status_code assert flow.response
code_int = flow.response.status_code
code_color = None code_color = None
if 200 <= code < 300: if 200 <= code_int < 300:
code_color = "green" code_color = "green"
elif 300 <= code < 400: elif 300 <= code_int < 400:
code_color = "magenta" code_color = "magenta"
elif 400 <= code < 600: elif 400 <= code_int < 600:
code_color = "red" code_color = "red"
code = click.style( code = click.style(
str(code), str(code_int),
fg=code_color, fg=code_color,
bold=True, bold=True,
blink=(code == 418) blink=(code_int == 418),
) )
if not flow.response.is_http2: if not flow.response.is_http2:

View File

@ -2,8 +2,8 @@ import time
import typing # noqa import typing # noqa
import uuid import uuid
from mitmproxy import connections from mitmproxy import controller
from mitmproxy import controller, exceptions # noqa from mitmproxy import exceptions
from mitmproxy import stateobject from mitmproxy import stateobject
from mitmproxy import version from mitmproxy import version
from mitmproxy.utils import compat from mitmproxy.utils import compat

View File

@ -236,3 +236,14 @@ def test_websocket():
f = tflow.twebsocketflow(client_conn=True, err=True) f = tflow.twebsocketflow(client_conn=True, err=True)
d.websocket_error(f) d.websocket_error(f)
assert "Error in WebSocket" in sio_err.getvalue() assert "Error in WebSocket" in sio_err.getvalue()
def test_http2():
sio = io.StringIO()
sio_err = io.StringIO()
d = dumper.Dumper(sio, sio_err)
with taddons.context(d):
f = tflow.tflow(resp=True)
f.response.http_version = b"HTTP/2.0"
d.response(f)
assert "HTTP/2.0 200 OK" in sio.getvalue()

View File

@ -0,0 +1,6 @@
from mitmproxy.utils import compat
def test_simple():
assert compat.Server
assert compat.Client