From 2f44b26b4cd014e03dd62a125d79af9b81663a93 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Wed, 3 Sep 2014 23:44:54 +0200 Subject: improve HTTPRequest syntax --- examples/redirect_requests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/redirect_requests.py') diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index a9a7e795..b57df2b2 100644 --- a/examples/redirect_requests.py +++ b/examples/redirect_requests.py @@ -7,12 +7,12 @@ 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"): + if flow.request.pretty_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.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() -- cgit v1.2.3 From 2a6337343a14f7f72c28d8bf5f24220f6d9ca6d0 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 5 Sep 2014 15:16:20 +0200 Subject: update docs, mostly revert 2f44b26b4cd014e03dd62a125d79af9b81663a93 --- examples/redirect_requests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'examples/redirect_requests.py') diff --git a/examples/redirect_requests.py b/examples/redirect_requests.py index cc642039..c5561839 100644 --- a/examples/redirect_requests.py +++ b/examples/redirect_requests.py @@ -6,7 +6,9 @@ This example shows two ways to redirect flows to other destinations. """ -def request(context, flow): +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", -- cgit v1.2.3