Return response directly + no request to target domain or server


#1

Hey,

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.

Thanks


#2

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 127.0.0.1, and then just return a 200 status code and a blank response for every request under that host.


#3

Hi, take a look at https://github.com/mitmproxy/mitmproxy/blob/master/examples/simple/send_reply_from_proxy.py. You may need to disable upstream cert fetching (--set upstream_cert=false) if the target server is entirely offline.