diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index acc848e18..726ed2c7a 100644 --- a/mitmproxy/proxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -8,6 +8,7 @@ from mitmproxy import connections # noqa from mitmproxy import exceptions from mitmproxy import http from mitmproxy import flow +from mitmproxy.net.http import url from mitmproxy.proxy.protocol import base from mitmproxy.proxy.protocol.websocket import WebSocketLayer from mitmproxy.net import websocket @@ -326,7 +327,10 @@ class HttpLayer(base.Layer): # update host header in reverse proxy mode if self.config.options.mode.startswith("reverse:") and not self.config.options.keep_host_header: - f.request.host_header = self.config.upstream_server.address[0] + f.request.host_header = url.hostport( + self.config.upstream_server.scheme, + *self.config.upstream_server.address + ) # Determine .scheme, .host and .port attributes for inline scripts. For # absolute-form requests, they are directly given in the request. For diff --git a/test/mitmproxy/proxy/test_server.py b/test/mitmproxy/proxy/test_server.py index 03e68e856..d092f73e5 100644 --- a/test/mitmproxy/proxy/test_server.py +++ b/test/mitmproxy/proxy/test_server.py @@ -452,7 +452,7 @@ class TestReverse(tservers.ReverseProxyTest, CommonMixin, TcpMixin): assert resp.status_code == 200 req = self.master.state.flows[0].request - assert req.host_header == "127.0.0.1" + assert req.host_header.startswith("127.0.0.1:") @pytest.mark.asyncio async def test_selfconnection(self):