期望:在本地程序发起的请求到达本地代理时做出修改,直接返回给目标程序,不再到达服务器。 mitmproxy==5.0.1,python==3.6.1, 程序结构:
class MyAdd:
def request(self, flow):
# do something in request
if "pan.baidu.com" in flow.request.pretty_url:
flow.kill()
if "test_kkk.cn" = flow.request.host:
with open('./init') as f_init:
flow.response.text = f_init.read()
flow.response.status_code = 200
def response(self, flow):
if "baidu.com" not in flow.request.pretty_url:
print(flow.response.text)
报错
flow.response.text = f_init.read()
AttributeError: 'NoneType' object has no attribute 'text'
而如果把 if "test_kkk.cn" = flow.request.host 放到 response 函数下则能正确修改,但不能满足“直接返回给目标程序,不再到达服务器”的要求。 该怎么实现呢