aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikhil Soni <krsoninikhil@gmail.com>2017-02-22 21:49:31 +0530
committerNikhil Soni <krsoninikhil@gmail.com>2017-02-22 21:49:31 +0530
commit14d8c91250aeb0e1e8d76b83bfa15c00c8091700 (patch)
tree888b427422e1bd6e8e5e1f25b8daa0230fae5545
parent391f28f78cf9f4ee2f82c69c7f5ce370b69b77cd (diff)
downloadmitmproxy-14d8c91250aeb0e1e8d76b83bfa15c00c8091700.tar.gz
mitmproxy-14d8c91250aeb0e1e8d76b83bfa15c00c8091700.tar.bz2
mitmproxy-14d8c91250aeb0e1e8d76b83bfa15c00c8091700.zip
Adds --keep-host-header option (#2039)
-rw-r--r--mitmproxy/options.py2
-rw-r--r--mitmproxy/proxy/protocol/http.py2
-rw-r--r--mitmproxy/tools/cmdline.py6
3 files changed, 9 insertions, 1 deletions
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index 2467b9dd..ff17fbbf 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 a7d56f24..a351ad66 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 bb0bb17a..18db3c8f 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):