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.
This commit is contained in:
Anderson Mesquita 2018-06-04 12:03:27 +02:00
parent 4fdc3d9e15
commit ba02a0b8b9
1 changed files with 15 additions and 0 deletions

View File

@ -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