Transparent mode, unable to prevent mitmproxy from contacting upstream server

Similar to:

Mitmproxy v4.0.3

I want to intercept the request from the client and send back a response without the upstream server ever being contacted. Everything works except the upstream server is always contacted with the original request.

I’ve created an add-on that has a request() method which:

  • Creates a http.HTTPResponse object
  • Assigns it to flow.response

Mitmproxy is being run with upstream_cert=false.

How do I prevent Mitmproxy from ever fulfilling the original request?

Thanks for your help!