Last active
April 21, 2026 10:13
-
-
Save johngian/51049c7c238cc708d629462048a6136b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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