# Return response directly + no request to target domain or server

**URL:** <https://discourse.mitmproxy.org/t/return-response-directly-no-request-to-target-domain-or-server/1160>\
**Category:** help\
**Created:** [August 6, 2018, 6:06pm UTC](https://discourse.mitmproxy.org/t/return-response-directly-no-request-to-target-domain-or-server/1160 "2018-08-06T18:06:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![systocrat](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@systocrat](https://discourse.mitmproxy.org/u/systocrat)\
**Post date:** [August 6, 2018, 6:06pm UTC](https://discourse.mitmproxy.org/t/return-response-directly-no-request-to-target-domain-or-server/1160/1 "2018-08-06T18:06:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![systocrat](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@systocrat](https://discourse.mitmproxy.org/u/systocrat)\
**Post date:** [August 6, 2018, 6:13pm UTC](https://discourse.mitmproxy.org/t/return-response-directly-no-request-to-target-domain-or-server/1160/2 "2018-08-06T18:13:03Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [August 6, 2018, 6:45pm UTC](https://discourse.mitmproxy.org/t/return-response-directly-no-request-to-target-domain-or-server/1160/3 "2018-08-06T18:45:42Z")

</div>

Hi, take a look at [https://github.com/mitmproxy/mitmproxy/blob/master/examples/simple/send\_reply\_from\_proxy.py](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.
