diff --git a/docs/scripts/api-events.py b/docs/scripts/api-events.py index 6a8b331f0..f365d8392 100644 --- a/docs/scripts/api-events.py +++ b/docs/scripts/api-events.py @@ -102,6 +102,7 @@ with outfile.open("w") as f, contextlib.redirect_stdout(f): http.HttpResponseHook, http.HttpErrorHook, http.HttpConnectHook, + http.HttpConnectUpstreamHook, ] ) diff --git a/mitmproxy/proxy/layers/http/__init__.py b/mitmproxy/proxy/layers/http/__init__.py index 3ad301573..806e65568 100644 --- a/mitmproxy/proxy/layers/http/__init__.py +++ b/mitmproxy/proxy/layers/http/__init__.py @@ -20,7 +20,7 @@ from ._base import HttpCommand, HttpConnection, ReceiveHttp, StreamId from ._events import HttpEvent, RequestData, RequestEndOfMessage, RequestHeaders, RequestProtocolError, RequestTrailers, \ ResponseData, ResponseEndOfMessage, ResponseHeaders, ResponseProtocolError, ResponseTrailers from ._hooks import HttpConnectHook, HttpErrorHook, HttpRequestHeadersHook, HttpRequestHook, HttpResponseHeadersHook, \ - HttpResponseHook + HttpResponseHook, HttpConnectUpstreamHook # noqa from ._http1 import Http1Client, Http1Connection, Http1Server from ._http2 import Http2Client, Http2Server from ...context import Context diff --git a/mitmproxy/proxy/layers/http/_upstream_proxy.py b/mitmproxy/proxy/layers/http/_upstream_proxy.py index df22f4abf..dc0c60ec4 100644 --- a/mitmproxy/proxy/layers/http/_upstream_proxy.py +++ b/mitmproxy/proxy/layers/http/_upstream_proxy.py @@ -34,6 +34,7 @@ class HttpUpstreamProxy(tunnel.TunnelLayer): @classmethod def make(cls, ctx: context.Context, send_connect: bool) -> tunnel.LayerStack: spec = ctx.server.via + assert spec assert spec.scheme in ("http", "https") http_proxy = connection.Server(spec.address) diff --git a/test/mitmproxy/addons/test_upstream_auth.py b/test/mitmproxy/addons/test_upstream_auth.py index ae037693c..8c8627275 100644 --- a/test/mitmproxy/addons/test_upstream_auth.py +++ b/test/mitmproxy/addons/test_upstream_auth.py @@ -45,9 +45,8 @@ def test_simple(): f = tflow.tflow() f.mode = "transparent" up.requestheaders(f) - assert "proxy-authorization" in f.request.headers + assert "authorization" in f.request.headers f = tflow.tflow() - f.mode = "upstream" - up.http_connect(f) + up.http_connect_upstream(f) assert "proxy-authorization" in f.request.headers diff --git a/test/mitmproxy/proxy/test_tunnel.py b/test/mitmproxy/proxy/test_tunnel.py index 68baad6db..b002c073d 100644 --- a/test/mitmproxy/proxy/test_tunnel.py +++ b/test/mitmproxy/proxy/test_tunnel.py @@ -266,3 +266,8 @@ def test_layer_stack(tctx): stack /= b assert stack[0] == a assert a.child_layer is b + + stack2 = tunnel.LayerStack() + stack2 /= TChildLayer(tctx) + stack2 /= stack + assert stack2[0].child_layer is a # type: ignore diff --git a/test/mitmproxy/tools/test_main.py b/test/mitmproxy/tools/test_main.py index f75f07ef2..7572d3649 100644 --- a/test/mitmproxy/tools/test_main.py +++ b/test/mitmproxy/tools/test_main.py @@ -11,7 +11,7 @@ def test_mitmweb(event_loop, tdata): main.mitmweb([ "--no-web-open-browser", "-s", tdata.path(shutdown_script), - "-q", "-p", "0", + "-q", "-p", "0", "--web-port", "0", ])