aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAmmonite <pierre@ambox.fr>2017-01-20 23:43:53 +0100
committerAmmonite <pierre@ambox.fr>2017-01-20 23:43:53 +0100
commita55eba3b379fc8e0d3377510fcc5aaa5c16da129 (patch)
tree3446f286269f580f368667e6d8301495befaf9ec /examples
parent0022c810e53eb0165abcdff2963100c78bcd4d7f (diff)
downloadmitmproxy-a55eba3b379fc8e0d3377510fcc5aaa5c16da129.tar.gz
mitmproxy-a55eba3b379fc8e0d3377510fcc5aaa5c16da129.tar.bz2
mitmproxy-a55eba3b379fc8e0d3377510fcc5aaa5c16da129.zip
Get the the original header in requestheaders instead of request
Diffstat (limited to 'examples')
-rw-r--r--examples/complex/dns_spoofing.py47
1 files changed, 28 insertions, 19 deletions
diff --git a/examples/complex/dns_spoofing.py b/examples/complex/dns_spoofing.py
index c020047f..b814e178 100644
--- a/examples/complex/dns_spoofing.py
+++ b/examples/complex/dns_spoofing.py
@@ -27,23 +27,32 @@ import re
# https://bugzilla.mozilla.org/show_bug.cgi?id=45891
parse_host_header = re.compile(r"^(?P<host>[^:]+|\[.+\])(?::(?P<port>\d+))?$")
+class DnsSpoofing:
+ def __init__(self):
+ self.hostHeader = None
-def request(flow):
- if flow.client_conn.ssl_established:
- flow.request.scheme = "https"
- sni = flow.client_conn.connection.get_servername()
- port = 443
- else:
- flow.request.scheme = "http"
- sni = None
- port = 80
-
- host_header = flow.request.pretty_host
- m = parse_host_header.match(host_header)
- if m:
- host_header = m.group("host").strip("[]")
- if m.group("port"):
- port = int(m.group("port"))
-
- flow.request.host = sni or host_header
- flow.request.port = port
+ def requestheaders(self, flow):
+ self.hostHeader = flow.request.headers.get('host')
+
+ def request(self, flow):
+ if flow.client_conn.ssl_established:
+ flow.request.scheme = "https"
+ sni = flow.client_conn.connection.get_servername()
+ port = 443
+ else:
+ flow.request.scheme = "http"
+ sni = None
+ port = 80
+
+ host_header = self.hostHeader
+ m = parse_host_header.match(host_header)
+ if m:
+ host_header = m.group("host").strip("[]")
+ if m.group("port"):
+ port = int(m.group("port"))
+
+ flow.request.host = sni or host_header
+ flow.request.port = port
+
+def start():
+ return DnsSpoofing()