我正在按照 Mitmproxy github examples 中的建议运行代理:
from libmproxy import proxy, flow
class MitmProxy(flow.FlowMaster):
def run(self):
try:
flow.FlowMaster.run(self)
except KeyboardInterrupt:
self.shutdown()
def handle_request(self, r):
f = flow.FlowMaster.handle_request(self, r)
if f:
r.reply()
return f
def handle_response(self, r):
f = flow.FlowMaster.handle_response(self, r)
if f:
r.reply()
return f
config = proxy.ProxyConfig(
cacert = os.path.expanduser("~/.ssl/mitmproxy.pem")
)
state = flow.State()
server = proxy.ProxyServer(config, 8083)
m = MitmProxy(server, state)
try:
m.run()
except Exception, e:
print e.message
m.shutdown()
我想处理每个请求/响应而不阻塞其他请求/响应, 为此,我需要使用并发装饰器和脚本
我的问题是:如何向在此配置中运行的代理加载和卸载脚本?
最佳答案
您可以使用并发模式加载脚本。
这是一个example对于这种用法
我更喜欢在流级别实现 mitmproxy 逻辑。
您可以使用此代码
def handle_response(self, r):
reply = f.response.reply
f.response.reply = controller.DummyReply()
if hasattr(reply, "q"):
f.response.reply.q = reply.q
def run():
pass
threading.Thread(target=run)
关于python - Mitmproxy使用python加载和卸载脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24156723/