mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-07-04 19:23:10 +02:00
15 lines
472 B
Python
15 lines
472 B
Python
"""Mitmproxy addon to simulate connection failures."""
|
|
|
|
from mitmproxy import http
|
|
|
|
|
|
def request(flow: http.HTTPFlow) -> None:
|
|
"""Intercept requests and simulate failures for specific hosts."""
|
|
# 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",
|
|
{"Content-Type": "text/plain"},
|
|
)
|