Return response directly + no request to target domain or server


I’d like to be able to write a script that will directly return a response to the client instead of attempting to carry through the request at all.

Is there support within mitmproxy to do this? I see from reading pydoc that mitmproxy.flow.Flow has some various methods like kill(), revert(), resume(), but I don’t think any of them do what I want them to do.

This might be an atypical use case, and if it helps, the client won’t be making a request to a real service, so skipping making the actual request isn’t really absolutely necessary- I just need to forge the response completely.


One way I can see to do this would be to create an entry in the hosts file for the nonexistent domain, point that host at a web server pointing at, and then just return a 200 status code and a blank response for every request under that host.

Hi, take a look at You may need to disable upstream cert fetching (--set upstream_cert=false) if the target server is entirely offline.

1 Like