From 04cda70d1a5686e8e08ced55f1aa66e7ee2ef4c0 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 29 Nov 2020 16:56:24 +0100 Subject: [PATCH] add example to shutdown the proxy master --- examples/addons/shutdown.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/addons/shutdown.py diff --git a/examples/addons/shutdown.py b/examples/addons/shutdown.py new file mode 100644 index 000000000..b0314f14d --- /dev/null +++ b/examples/addons/shutdown.py @@ -0,0 +1,18 @@ +""" +A simple way of shutting down the mitmproxy instance to stop everything. + +Usage: + + mitmproxy -s shutdown.py + + and then send a HTTP request to trigger the shutdown: + curl --proxy localhost:8080 http://example.com/path +""" +from mitmproxy import ctx, http + + +def request(flow: http.HTTPFlow) -> None: + # a random condition to make this example a bit more interactive + if flow.request.pretty_url == "http://example.com/path": + ctx.log.info("Shutting down everything...") + ctx.master.shutdown()