前言
mitmproxy 可以抓到请求后重定向到另外一个地址,也可以自定义返回的 response 内容
重定向请求
在实际工作中,调试接口的时候,有时候需要把线上的接口地址替换成本地地址去调试接口,可以用转发域名的方式
"""Redirect HTTP requests to another server."""
from mitmproxy import http
def request(flow: http.HTTPFlow) -> None:
# pretty_host takes the "Host" header of the request into account,
# which is useful in transparent mode where we usually only have the IP
# otherwise.
if flow.request.pretty_host == "example.org":
flow.request.host = "mitmproxy.org"
mock 返回指定数据
抓到对应接口,也可以指定返回 response 内容
"""Send a reply from the proxy without sending any data to the remote server."""
from mitmproxy import http
def request(flow: