# Add header based on value in response

**URL:** <https://discourse.mitmproxy.org/t/add-header-based-on-value-in-response/1283>\
**Category:** help\
**Created:** [October 18, 2018, 10:20pm UTC](https://discourse.mitmproxy.org/t/add-header-based-on-value-in-response/1283 "2018-10-18T22:20:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![leesoh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/leesoh/32/364_2.png) [@leesoh](https://discourse.mitmproxy.org/u/leesoh)\
**Post date:** [October 18, 2018, 10:20pm UTC](https://discourse.mitmproxy.org/t/add-header-based-on-value-in-response/1283/1 "2018-10-18T22:20:47Z")

</div>

Hi there,

I have a cookie value that changes every five minutes or so and I need to augment Burp’s session handling to accommodate. The cookie should be copied to a header and included in all outgoing requests. Incoming requests should be monitored for updated cookies. If one is seen, the value sent in the header must also be updated.

Here’s what I’ve got so far:

```
from mitmproxy import http
from mitmproxy import ctx

class Bearer:
    def __init__ (self):
        self.auth_token = ""

    def response(self, flow: http.HTTPFlow):
        headers = flow.response.cookies
        self.auth_token = headers.get("Authorization", "")
        self.refresh_token = headers.get("Refresh-Token", "")
        if self.auth_token:
            ctx.log.info(f"Authorization Updated: {self.auth_token}")
        if self.refresh_token:
            ctx.log.info(f"Refresh-Token Updated: {self.refresh_token}")

    def request(self, flow: http.HTTPFlow) -> None:        
        if self.auth_token:
            flow.request.headers["Authorization"] = self.auth_token[0]

def start():
    return Bearer()
```

---

<div class="post-metadata">

**Author:** ![leesoh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/leesoh/32/364_2.png) [@leesoh](https://discourse.mitmproxy.org/u/leesoh)\
**Post date:** [October 19, 2018, 3:06pm UTC](https://discourse.mitmproxy.org/t/add-header-based-on-value-in-response/1283/2 "2018-10-19T15:06:19Z")

</div>

Layer 8 issue. I don’t want to talk about it.
