Skip to content

Instantly share code, notes, and snippets.

@johngian
Last active April 21, 2026 10:13
Show Gist options
  • Select an option

  • Save johngian/51049c7c238cc708d629462048a6136b to your computer and use it in GitHub Desktop.

Select an option

Save johngian/51049c7c238cc708d629462048a6136b to your computer and use it in GitHub Desktop.
import asyncio
import os
from mitmproxy import ctx, http
async def replay(flow: http.HTTPFlow):
ctx.master.commands.call("replay.client", [flow])
class Retry503:
def __init__(self):
self.max_retries = os.environ.get("MAX_RETRIES", 3)
def response(self, flow: http.HTTPFlow) -> None:
retry_count = flow.metadata.get("retry_count", 0)
if flow.response and flow.response.status_code == 503 and retry_count < self.max_retries:
retry_count += 1
ctx.log.info(f"503 received for {flow.request.url} - retry count {retry_count}")
flow.metadata["retry_count"] = retry_count
retry_flow = flow.copy()
asyncio.ensure_future(replay(retry_flow))
addons = [Retry503()]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment