diff options
author | Aldo Cortesi <aldo@corte.si> | 2014-09-07 12:59:35 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2014-09-07 12:59:35 +1200 |
commit | 3d62e90dbf7ea05283e16752531a261e53a4bb47 (patch) | |
tree | c3f5aed62bcf13378522968a1c77375dc8102b53 /examples/redirect_requests.py | |
parent | 0e0cff638c1e055275e77e2af0ae540542f77197 (diff) | |
parent | fdd7b2f108717900e39e3d0ab220ee65b79304ef (diff) | |
download | mitmproxy-3d62e90dbf7ea05283e16752531a261e53a4bb47.tar.gz mitmproxy-3d62e90dbf7ea05283e16752531a261e53a4bb47.tar.bz2 mitmproxy-3d62e90dbf7ea05283e16752531a261e53a4bb47.zip |
Merge pull request #342 from mitmproxy/server_change_api
Server change api
Diffstat (limited to 'examples/redirect_requests.py')
-rw-r--r-- | examples/redirect_requests.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index 530da200..c5561839 100644 --- a/examples/redirect_requests.py +++ b/examples/redirect_requests.py @@ -6,13 +6,15 @@ This example shows two ways to redirect flows to other destinations. """ -def request(context, flow): - if flow.request.get_host(hostheader=True).endswith("example.com"): +def request(ctx, flow): + # pretty_host(hostheader=True) takes the Host: header of the request into account, + # which is useful in transparent mode where we usually only have the IP otherwise. + if flow.request.pretty_host(hostheader=True).endswith("example.com"): resp = HTTPResponse( [1, 1], 200, "OK", ODictCaseless([["Content-Type", "text/html"]]), "helloworld") flow.reply(resp) - if flow.request.get_host(hostheader=True).endswith("example.org"): + if flow.request.pretty_host(hostheader=True).endswith("example.org"): flow.request.host = "mitmproxy.org" - flow.request.headers["Host"] = ["mitmproxy.org"] + flow.request.update_host_header() |