aboutsummaryrefslogtreecommitdiffstats
path: root/examples/change_upstream_proxy.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-07 18:01:30 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-07 18:01:37 +0200
commitac27d1236fdbf69c826b5d2bb4c69ebbe8ab40a1 (patch)
treeac0e57ea2e7bb540c23fb1149d900a7d24e50b0b /examples/change_upstream_proxy.py
parent58ea19869897deee5d561d2c31a03233c047fbe3 (diff)
downloadmitmproxy-ac27d1236fdbf69c826b5d2bb4c69ebbe8ab40a1.tar.gz
mitmproxy-ac27d1236fdbf69c826b5d2bb4c69ebbe8ab40a1.tar.bz2
mitmproxy-ac27d1236fdbf69c826b5d2bb4c69ebbe8ab40a1.zip
improve change_server api, add example how to change the upstream server
Diffstat (limited to 'examples/change_upstream_proxy.py')
-rw-r--r--examples/change_upstream_proxy.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/examples/change_upstream_proxy.py b/examples/change_upstream_proxy.py
new file mode 100644
index 00000000..2e4c6080
--- /dev/null
+++ b/examples/change_upstream_proxy.py
@@ -0,0 +1,17 @@
+# This scripts demonstrates how mitmproxy can switch to a different upstream proxy
+# in upstream proxy mode.
+#
+# Usage: mitmdump -s "change_upstream_proxy.py host"
+from libmproxy.protocol.http import send_connect_request
+
+def should_redirect(flow):
+ return (flow.request.host == "example.com")
+alternative_upstream_proxy = ("localhost",8082)
+
+def request(ctx, flow):
+ if flow.live and should_redirect(flow):
+
+ server_changed = flow.live.change_server(alternative_upstream_proxy, persistent_change=True)
+ if flow.request.scheme == "https" and server_changed:
+ send_connect_request(flow.live.c.server_conn, flow.request.host, flow.request.port)
+ flow.live.c.establish_ssl(server=True)