mirror of
https://github.com/mitmproxy/mitmproxy.git
synced 2025-01-26 07:44:35 +00:00
fix #274
This commit is contained in:
parent
c88613f596
commit
f4a1459ebe
@ -7,12 +7,12 @@ This example shows two ways to redirect flows to other destinations.
|
||||
|
||||
|
||||
def request(context, flow):
|
||||
if flow.request.host.endswith("example.com"):
|
||||
if flow.request.get_host(hostheader=True).endswith("example.com"):
|
||||
resp = HTTPResponse(
|
||||
[1, 1], 200, "OK",
|
||||
ODictCaseless([["Content-Type", "text/html"]]),
|
||||
"helloworld")
|
||||
flow.request.reply(resp)
|
||||
if flow.request.host.endswith("example.org"):
|
||||
if flow.request.get_host(hostheader=True).endswith("example.org"):
|
||||
flow.request.host = "mitmproxy.org"
|
||||
flow.request.headers["Host"] = ["mitmproxy.org"]
|
||||
|
@ -464,9 +464,13 @@ class HTTPRequest(HTTPMessage):
|
||||
def get_host(self, hostheader=False):
|
||||
"""
|
||||
Heuristic to get the host of the request.
|
||||
The host is not necessarily equal to the TCP destination of the request,
|
||||
for example on a transparently proxified absolute-form request to an upstream HTTP proxy.
|
||||
|
||||
Note that get_host() does not always return the TCP destination of the request,
|
||||
e.g. on a transparently intercepted request to an unrelated HTTP proxy.
|
||||
|
||||
If hostheader is set to True, the Host: header will be used as additional (and preferred) data source.
|
||||
This is handy in transparent mode, where only the ip of the destination is known, but not the
|
||||
resolved name. This is disabled by default, as an attacker may spoof the host header to confuse an analyst.
|
||||
"""
|
||||
host = None
|
||||
if hostheader:
|
||||
|
Loading…
x
Reference in New Issue
Block a user