From 009c124dc8baf19f22c67c71430f2ecfe1a778c3 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Thu, 10 Dec 2020 09:01:07 +0100 Subject: [PATCH] fix #4280 --- mitmproxy/proxy/protocol/http.py | 6 +++++- test/mitmproxy/proxy/test_server.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index efe5740e3..cb0e3a459 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 websockets @@ -324,7 +325,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):