Scripting API Guide
Extend RelayCraft's capabilities using Python. The scripting API is fully compatible with mitmproxy.
Basic Structure
A script is a Python file that defines event handlers. The most common handlers are request and response.
from mitmproxy import http
def request(flow: http.HTTPFlow):
# Called when a client request is received
if "example.com" in flow.request.pretty_host:
flow.request.headers["X-Debug"] = "True"
def response(flow: http.HTTPFlow):
# Called when a server response is received
if flow.response.status_code == 404:
flow.response.status_code = 200
flow.response.content = b"Fixed by RelayCraft!"Common Use Cases
1. Redirecting Traffic
Useful for pointing a production app to a local development server.
def request(flow):
if flow.request.host == "api.production.com":
flow.request.host = "localhost"
flow.request.port = 3000
flow.request.scheme = "http"Pro Tip
You can modify response bodies on the fly to test edge cases in your frontend application without changing backend code.