2014-05-15 12:37:05 +00:00
|
|
|
from libmproxy.protocol.http import HTTPResponse
|
2013-04-07 17:16:01 +00:00
|
|
|
from netlib.odict import ODictCaseless
|
|
|
|
|
|
|
|
"""
|
|
|
|
This example shows two ways to redirect flows to other destinations.
|
|
|
|
"""
|
|
|
|
|
2014-05-15 12:37:05 +00:00
|
|
|
|
2013-04-07 17:16:01 +00:00
|
|
|
def request(context, flow):
|
2014-08-08 23:02:58 +00:00
|
|
|
if flow.request.get_host(hostheader=True).endswith("example.com"):
|
2014-05-15 12:37:05 +00:00
|
|
|
resp = HTTPResponse(
|
|
|
|
[1, 1], 200, "OK",
|
|
|
|
ODictCaseless([["Content-Type", "text/html"]]),
|
|
|
|
"helloworld")
|
2013-04-07 17:16:01 +00:00
|
|
|
flow.request.reply(resp)
|
2014-08-08 23:02:58 +00:00
|
|
|
if flow.request.get_host(hostheader=True).endswith("example.org"):
|
2013-04-07 17:16:01 +00:00
|
|
|
flow.request.host = "mitmproxy.org"
|
|
|
|
flow.request.headers["Host"] = ["mitmproxy.org"]
|