maplocal.py
"""Send a reply from the proxy without sending any data to the remote server.""" from mitmproxy import http def request(flow: http.HTTPFlow) -> None: if flow.request.pretty_url == "http://example.com/path": #if "quote.json" in flow.request.pretty_url and "x=" in flow.request.pretty_url: with open("./maplocal_response.json",encoding="utf8") as f: flow.response = http.HTTPResponse.make( 200, # (optional) status code f.read(), # (optional) content {"Content-Type": "application/json"} # (optional) headers )maplocal_response.json
{ "errcode": 401, "errmsg": "用户未登录或会话已超时" }运行
mitmdump -p 9999 -s maplocal.py curl -s http://example.com/path -x 127.0.0.1:9999rewrite.py
from mitmproxy import http import json def response(flow: http.HTTPFlow): if flow.request.pretty_url == "http://example.com/path": data = json.loads(flow.response.content) data['data']['errcode'] = data['data']['errcode'] + "100" flow.response.text = json.dumps(data)