# Addon intercepting request and responding to it

**URL:** <https://discourse.mitmproxy.org/t/addon-intercepting-request-and-responding-to-it/1422>\
**Category:** help\
**Created:** [February 10, 2019, 8:58pm UTC](https://discourse.mitmproxy.org/t/addon-intercepting-request-and-responding-to-it/1422 "2019-02-10T20:58:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![WanderingBrooks](https://avatars.discourse-cdn.com/v4/letter/w/b38774/32.png) [@WanderingBrooks](https://discourse.mitmproxy.org/u/WanderingBrooks)\
**Post date:** [February 10, 2019, 8:58pm UTC](https://discourse.mitmproxy.org/t/addon-intercepting-request-and-responding-to-it/1422/1 "2019-02-10T20:58:34Z")

</div>

Hi,

I’m trying to write an addon and want to reply to a request in the request function [here](https://github.com/mitmproxy/mitmproxy/blob/3cd37652709292cffa1bc733134cef5483489341/examples/addons/events.py#L29). How do I intercept this request and respond to it as if I am the server my device wants to connect too. The functionality I’m looking for is something like the below

```
def request(self, flow):
  resp = http.HTTPResponse(
        http_version=b"HTTP/2.0",
        status_code=200,
        reason=b'OK',
        headers=flow.request.headers,
        content=the content I want to send to my device
    )
    flow.reply.send(resp)

```

However I can’t find anything like this. Any information would be helpful.

---

<div class="post-metadata">

**Author:** ![WanderingBrooks](https://avatars.discourse-cdn.com/v4/letter/w/b38774/32.png) [@WanderingBrooks](https://discourse.mitmproxy.org/u/WanderingBrooks)\
**Post date:** [February 12, 2019, 1:37am UTC](https://discourse.mitmproxy.org/t/addon-intercepting-request-and-responding-to-it/1422/2 "2019-02-12T01:37:28Z")

</div>

I figured out how to do it. So if anyone else runs into this issue. Its not reply its response so this example above would look like

```
def request(self, flow):
  flow.intercept()
  resp = http.HTTPResponse(
      http_version=b"HTTP/2.0",
      status_code=200,
      reason=b'OK',
      headers=flow.request.headers,
      content=content I want to send to my device
   )
   flow.response = resp
   flow.resume()
```

---

<div class="post-metadata">

**Author:** ![happytree](https://avatars.discourse-cdn.com/v4/letter/h/e9c0ed/32.png) [@happytree](https://discourse.mitmproxy.org/u/happytree)\
**Post date:** [February 18, 2019, 4:40am UTC](https://discourse.mitmproxy.org/t/addon-intercepting-request-and-responding-to-it/1422/3 "2019-02-18T04:40:59Z")

</div>

Thanks a lot, your answer helped me, I didn’t know `flow.intercept()` and `flow.resume()` existed and they solve my use case, thanks!
