aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAmmonite <pierre@ambox.fr>2017-01-29 14:33:53 +0100
committerAmmonite <pierre@ambox.fr>2017-01-29 14:33:53 +0100
commitc2c6050df398ecb922cf040ea7c5c3ab8cdeac03 (patch)
treeef6ab5f9c2902c01cc5b06831325651958d67111 /examples
parent0ca1916f1bb8728af3289f5fe975951af97f4ffa (diff)
downloadmitmproxy-c2c6050df398ecb922cf040ea7c5c3ab8cdeac03.tar.gz
mitmproxy-c2c6050df398ecb922cf040ea7c5c3ab8cdeac03.tar.bz2
mitmproxy-c2c6050df398ecb922cf040ea7c5c3ab8cdeac03.zip
Store original host in flow metadata
Diffstat (limited to 'examples')
-rw-r--r--examples/complex/dns_spoofing.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/examples/complex/dns_spoofing.py b/examples/complex/dns_spoofing.py
index 1d703537..5e6cf978 100644
--- a/examples/complex/dns_spoofing.py
+++ b/examples/complex/dns_spoofing.py
@@ -29,15 +29,12 @@ parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$")
class Rerouter:
- def __init__(self):
- self.host_header = None
-
def requestheaders(self, flow):
"""
The original host header is retrieved early
before flow.request is replaced by mitmproxy new outgoing request
"""
- self.host_header = flow.request.headers.get('host')
+ flow.metadata["original_host"] = flow.request.headers["Host"]
def request(self, flow):
if flow.client_conn.ssl_established:
@@ -49,13 +46,14 @@ class Rerouter:
sni = None
port = 80
- m = parse_host_header.match(self.host_header)
+ host_header = flow.metadata["original_host"]
+ m = parse_host_header.match(host_header)
if m:
- self.host_header = m.group("host").strip("[]")
+ host_header = m.group("host").strip("[]")
if m.group("port"):
port = int(m.group("port"))
- flow.request.host = sni or self.host_header
+ flow.request.host = sni or host_header
flow.request.port = port