2025-11-30 14:45:55 +01:00
|
|
|
"""Mitmproxy addon to simulate connection failures."""
|
|
|
|
|
|
2024-10-15 07:22:10 +02:00
|
|
|
from mitmproxy import http
|
|
|
|
|
|
2025-11-30 13:42:16 +01:00
|
|
|
|
2024-10-15 07:22:10 +02:00
|
|
|
def request(flow: http.HTTPFlow) -> None:
|
2025-11-30 14:45:55 +01:00
|
|
|
"""Intercept requests and simulate failures for specific hosts."""
|
2024-10-15 07:22:10 +02:00
|
|
|
# Only intercept traffic to example.com
|
|
|
|
|
if "example.com" in flow.request.host:
|
|
|
|
|
flow.response = http.Response.make(
|
|
|
|
|
502, # Bad Gateway status code
|
|
|
|
|
b"Simulated connection failure",
|
2025-11-30 13:42:16 +01:00
|
|
|
{"Content-Type": "text/plain"},
|
2024-10-15 07:22:10 +02:00
|
|
|
)
|