Replay and change upstream proxy server

Hello,

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, flow.live 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 flow.live:
        address = ('some_host', 8080)
        flow.live.change_upstream_proxy_server(address)

def responseheaders(self, flow: mitmproxy.http.HTTPFlow):
    if flow.response.status_code == 403:
        flow = flow.copy()
        ctx.master.commands.call("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 flow.live and flow.response.status_code == 403:
                address = ('some_host', 8080)
                flow.live.change_upstream_proxy_server(address)
                flow.reply.kill(force=True)
                flow.response = None
                ctx.master.commands.call("replay.server", [flow])