From 14d8c91250aeb0e1e8d76b83bfa15c00c8091700 Mon Sep 17 00:00:00 2001 From: Nikhil Soni Date: Wed, 22 Feb 2017 21:49:31 +0530 Subject: [PATCH] Adds --keep-host-header option (#2039) --- mitmproxy/options.py | 2 ++ mitmproxy/proxy/protocol/http.py | 2 +- mitmproxy/tools/cmdline.py | 6 ++++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 2467b9dda..ff17fbbfd 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -72,6 +72,7 @@ class Options(optmanager.OptManager): upstream_bind_address: str = "", mode: str = "regular", no_upstream_cert: bool = False, + keep_host_header: bool = False, http2: bool = True, http2_priority: bool = False, @@ -162,6 +163,7 @@ class Options(optmanager.OptManager): self.upstream_bind_address = upstream_bind_address self.mode = mode self.no_upstream_cert = no_upstream_cert + self.keep_host_header = keep_host_header self.http2 = http2 self.http2_priority = http2_priority diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index a7d56f24b..a351ad666 100644 --- a/mitmproxy/proxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -290,7 +290,7 @@ class HttpLayer(base.Layer): request.first_line_format = "relative" # update host header in reverse proxy mode - if self.config.options.mode == "reverse": + if self.config.options.mode == "reverse" and not self.config.options.keep_host_header: f.request.host_header = self.config.upstream_server.address.host # Determine .scheme, .host and .port attributes for inline scripts. For diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py index bb0bb17a1..18db3c8f0 100644 --- a/mitmproxy/tools/cmdline.py +++ b/mitmproxy/tools/cmdline.py @@ -112,6 +112,7 @@ def get_common_options(args): replacements=args.replacements, replacement_files=args.replacement_files, setheaders=args.setheaders, + keep_host_header=args.keep_host_header, server_replay=args.server_replay, scripts=args.scripts, stickycookie=stickycookie, @@ -387,6 +388,11 @@ def proxy_options(parser): action="store", type=str, dest="upstream_bind_address", help="Address to bind upstream requests to (defaults to none)" ) + group.add_argument( + "--keep-host-header", + action="store_true", dest="keep_host_header", + help="Keep the host header as proxy addres" + ) def proxy_ssl_options(parser):