2013-04-07 17:16:01 +00:00
|
|
|
"""
|
|
|
|
This example shows two ways to redirect flows to other destinations.
|
|
|
|
"""
|
2016-02-16 19:49:10 +00:00
|
|
|
from mitmproxy.models import HTTPResponse
|
2014-05-15 12:37:05 +00:00
|
|
|
|
2016-05-29 08:23:39 +00:00
|
|
|
|
2016-07-08 01:37:33 +00:00
|
|
|
def request(flow):
|
2015-09-25 23:23:59 +00:00
|
|
|
# pretty_host takes the "Host" header of the request into account,
|
2015-05-30 00:03:28 +00:00
|
|
|
# which is useful in transparent mode where we usually only have the IP
|
|
|
|
# otherwise.
|
2014-09-08 14:02:31 +00:00
|
|
|
|
|
|
|
# Method 1: Answer with a locally generated response
|
2015-09-25 23:23:59 +00:00
|
|
|
if flow.request.pretty_host.endswith("example.com"):
|
2016-10-17 06:49:54 +00:00
|
|
|
flow.response = HTTPResponse.make(200, b"Hello World", {"Content-Type": "text/html"})
|
2014-09-08 14:02:31 +00:00
|
|
|
|
|
|
|
# Method 2: Redirect the request to a different server
|
2015-09-25 23:23:59 +00:00
|
|
|
if flow.request.pretty_host.endswith("example.org"):
|
2016-01-08 15:02:27 +00:00
|
|
|
flow.request.host = "mitmproxy.org"
|