From 26631621eef3825b8741eaa7dcc0044bcb7451dd Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Sat, 3 Oct 2015 14:48:42 +0200 Subject: [PATCH] fix #786 --- libmproxy/protocol/http.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index 50765e508..8e56c699e 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -382,6 +382,7 @@ class HttpLayer(Layer): def get_request_from_client(self): request = self.read_request() if request.headers.get("expect", "").lower() == "100-continue": + # TODO: We may have to use send_response_headers for HTTP2 here. self.send_response(expect_continue_response) request.headers.pop("expect") request.body = b"".join(self.read_request_body(request)) @@ -491,8 +492,12 @@ class HttpLayer(Layer): if flow.request.form_in == "authority": flow.request.scheme = "http" # pseudo value else: + # Setting request.host also updates the host header, which we want to preserve + host_header = flow.request.headers.get("host", None) flow.request.host = self.__original_server_conn.address.host flow.request.port = self.__original_server_conn.address.port + if host_header: + flow.request.headers["host"] = host_header # TODO: This does not really work if we change the first request and --no-upstream-cert is enabled flow.request.scheme = "https" if self.__original_server_conn.tls_established else "http"