From 4fdc3d9e157965af6cf6220e0b7b5b7e5dc179bd Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Mon, 4 Jun 2018 11:48:30 +0200 Subject: [PATCH 1/2] Rename scripting file In order to add the more scripting examples, it makes sense to rename this file and avoid confusion. --- docs/src/content/addons-scripting.md | 2 +- examples/addons/{scripting.py => scripting-headers.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename examples/addons/{scripting.py => scripting-headers.py} (100%) diff --git a/docs/src/content/addons-scripting.md b/docs/src/content/addons-scripting.md index e31d291a9..f9973b9ef 100644 --- a/docs/src/content/addons-scripting.md +++ b/docs/src/content/addons-scripting.md @@ -14,4 +14,4 @@ handler functions in the module scope. For instance, here is a complete script that adds a header to every request. -{{< example src="examples/addons/scripting.py" lang="py" >}} \ No newline at end of file +{{< example src="examples/addons/scripting-headers.py" lang="py" >}} diff --git a/examples/addons/scripting.py b/examples/addons/scripting-headers.py similarity index 100% rename from examples/addons/scripting.py rename to examples/addons/scripting-headers.py From ba02a0b8b9a068697b39b0f6c7ac36a2a479e0bc Mon Sep 17 00:00:00 2001 From: Anderson Mesquita Date: Mon, 4 Jun 2018 12:03:27 +0200 Subject: [PATCH 2/2] Add example to intercept/change specific requests This example captures requests to a specific URL and returns an arbitrary response instead. It's common enough that is useful to have in the docs. It also adds links to the Request and Response classes to help developers writing scripts. --- docs/src/content/addons-scripting.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/src/content/addons-scripting.md b/docs/src/content/addons-scripting.md index f9973b9ef..4e9916ca8 100644 --- a/docs/src/content/addons-scripting.md +++ b/docs/src/content/addons-scripting.md @@ -15,3 +15,18 @@ that adds a header to every request. {{< example src="examples/addons/scripting-headers.py" lang="py" >}} + + +Here's another example that intercepts requests to a particular URL and sends +an arbitrary response instead: + +{{< example src="examples/simple/send_reply_from_proxy.py" lang="py" >}} + + +You can look at the [http][] module, or the [Request][], and +[Response][] classes for other attributes that you can use when +scripting. + +[http][]: https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/http.py +[Request]: https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/net/http/request.py +[Response]: https://github.com/mitmproxy/mitmproxy/blob/master/mitmproxy/net/http/response.py