Replay and change upstream proxy server


I’m using python addons and I’m trying to change the upstream proxy server if a time out or a specific error occur in the response.

I’ve seen both work independently but when my flow is duplicated and sent through the ‘replay.client’ command, is not a “HttpLayer” object anymore and become just True giving me of course the following error: “AttributeError: ‘bool’ object has no attribute ‘change_upstream_proxy_server’”

Here is my code:

def request(self, flow: mitmproxy.http.HTTPFlow):
    if flow.request.is_replay and
        address = ('some_host', 8080)

def responseheaders(self, flow: mitmproxy.http.HTTPFlow):
    if flow.response.status_code == 403:
        flow = flow.copy()"replay.client", [flow])

Am I missing something ?

I finally managed to do what I wanted with the following code only:

def response(self, flow: mitmproxy.http.HTTPFlow):
        if and flow.response.status_code == 403:
                address = ('some_host', 8080)
                flow.response = None
      "replay.server", [flow])