def __init__(self, options, server, with_termlog=False) -> None: master.Master.__init__(self, options, server) self.has_errored = False self.monitor_host = 'monitor.zkt' self.monitor_port = 80 # TODO: 考虑用tornado替代flask以减少冗余依赖 # 将Flask的实例注入mitmproxy self.addons.add( wsgiapp.WSGIApp(app, self.monitor_host, self.monitor_port)) self.db_session = DBSession() if with_termlog: self.addons.add(termlog.TermLog()) self.addons.add(*addons.default_addons()) if not self.options.no_server: self.add_log("代理服务运行于 http://{}".format(server.address), "info")
def addons(self): return [ wsgiapp.WSGIApp(tapp, "testapp", 80), wsgiapp.WSGIApp(errapp, "errapp", 80) ]
def start(opts): # Host app at the magic domain "proxapp" on port 80. Requests to this # domain and port combination will now be routed to the WSGI app instance. return wsgiapp.WSGIApp(app, "proxapp", 80)
""" Host a WSGI app in mitmproxy. This example shows how to graft a WSGI app onto mitmproxy. In this instance, we're using the Flask framework (http://flask.pocoo.org/) to expose a single simplest-possible page. """ from flask import Flask from mitmproxy.addons import wsgiapp app = Flask("proxapp") @app.route('/') def hello_world() -> str: return 'Hello World!' addons = [ # Host app at the magic domain "example.com" on port 80. Requests to this # domain and port combination will now be routed to the WSGI app instance. wsgiapp.WSGIApp(app, "example.com", 80) # SSL works too, but the magic domain needs to be resolvable from the mitmproxy machine due to mitmproxy's design. # mitmproxy will connect to said domain and use serve its certificate (unless --no-upstream-cert is set) # but won't send any data. # mitmproxy.ctx.master.apps.add(app, "example.com", 443) ]
def cc(host, port): return wsgiapp.WSGIApp(create_application(), host, port)