mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
Remove external app option, make tick timeout explicit
This commit is contained in:
parent
81e3a6e8e6
commit
17868f61a9
@ -156,7 +156,6 @@ def get_common_options(options):
|
||||
app=options.app,
|
||||
app_host=options.app_host,
|
||||
app_port=options.app_port,
|
||||
app_external=options.app_external,
|
||||
|
||||
anticache=options.anticache,
|
||||
anticomp=options.anticomp,
|
||||
@ -333,11 +332,6 @@ def common_options(parser):
|
||||
action="store", dest="app_port", default=APP_PORT, type=int, metavar="80",
|
||||
help="Port to serve the app from."
|
||||
)
|
||||
group.add_argument(
|
||||
"--app-external",
|
||||
action="store_true", dest="app_external",
|
||||
help="Serve the app outside of the proxy."
|
||||
)
|
||||
|
||||
group = parser.add_argument_group("Client Replay")
|
||||
group.add_argument(
|
||||
|
@ -435,7 +435,7 @@ class ConsoleMaster(flow.FlowMaster):
|
||||
sys.exit(1)
|
||||
|
||||
if options.app:
|
||||
self.start_app(self.options.app_host, self.options.app_port, self.options.app_external)
|
||||
self.start_app(self.options.app_host, self.options.app_port)
|
||||
|
||||
def start_stream(self, path):
|
||||
path = os.path.expanduser(path)
|
||||
|
@ -108,7 +108,7 @@ class Master:
|
||||
self.should_exit.clear()
|
||||
self.server.start_slave(Slave, Channel(self.masterq, self.should_exit))
|
||||
while not self.should_exit.is_set():
|
||||
self.tick(self.masterq)
|
||||
self.tick(self.masterq, 0.01)
|
||||
self.shutdown()
|
||||
|
||||
def handle(self, mtype, obj):
|
||||
|
@ -10,7 +10,6 @@ class DumpError(Exception): pass
|
||||
class Options(object):
|
||||
attributes = [
|
||||
"app",
|
||||
"app_external",
|
||||
"app_host",
|
||||
"app_port",
|
||||
"anticache",
|
||||
@ -135,7 +134,7 @@ class DumpMaster(flow.FlowMaster):
|
||||
self.add_event("Flow file corrupted. Stopped loading.", "error")
|
||||
|
||||
if self.o.app:
|
||||
self.start_app(self.o.app_host, self.o.app_port, self.o.app_external)
|
||||
self.start_app(self.o.app_host, self.o.app_port)
|
||||
|
||||
def _readflow(self, path):
|
||||
path = os.path.expanduser(path)
|
||||
|
@ -451,39 +451,12 @@ class FlowMaster(controller.Master):
|
||||
self.stream = None
|
||||
self.apps = AppRegistry()
|
||||
|
||||
def start_app(self, host, port, external):
|
||||
if not external:
|
||||
self.apps.add(
|
||||
app.mapp,
|
||||
host,
|
||||
port
|
||||
)
|
||||
else:
|
||||
@app.mapp.before_request
|
||||
def patch_environ(*args, **kwargs):
|
||||
flask.request.environ["mitmproxy.master"] = self
|
||||
|
||||
# the only absurd way to shut down a flask/werkzeug server.
|
||||
# http://flask.pocoo.org/snippets/67/
|
||||
shutdown_secret = base64.b32encode(os.urandom(30))
|
||||
|
||||
@app.mapp.route('/shutdown/<secret>')
|
||||
def shutdown(secret):
|
||||
if secret == shutdown_secret:
|
||||
flask.request.environ.get('werkzeug.server.shutdown')()
|
||||
|
||||
# Workaround: Monkey-patch shutdown function to stop the app.
|
||||
# Improve this when we switch werkzeugs http server for something useful.
|
||||
_shutdown = self.shutdown
|
||||
def _shutdownwrap():
|
||||
_shutdown()
|
||||
requests.get("http://%s:%s/shutdown/%s" % (host, port, shutdown_secret))
|
||||
self.shutdown = _shutdownwrap
|
||||
|
||||
threading.Thread(target=app.mapp.run, kwargs={
|
||||
"use_reloader": False,
|
||||
"host": host,
|
||||
"port": port}).start()
|
||||
def start_app(self, host, port):
|
||||
self.apps.add(
|
||||
app.mapp,
|
||||
host,
|
||||
port
|
||||
)
|
||||
|
||||
def add_event(self, e, level="info"):
|
||||
"""
|
||||
|
@ -1,5 +1,6 @@
|
||||
|
||||
import tornado.ioloop
|
||||
import tornado.httpserver
|
||||
from .. import controller, utils, flow, script, proxy
|
||||
|
||||
|
||||
|
@ -103,7 +103,7 @@ class TestClientPlaybackState:
|
||||
|
||||
q = Queue.Queue()
|
||||
fm.state.clear()
|
||||
fm.tick(q)
|
||||
fm.tick(q, timeout=0)
|
||||
|
||||
fm.stop_client_playback()
|
||||
assert not fm.client_playback
|
||||
@ -645,7 +645,7 @@ class TestFlowMaster:
|
||||
|
||||
q = Queue.Queue()
|
||||
assert not fm.state.flow_count()
|
||||
fm.tick(q)
|
||||
fm.tick(q, 0)
|
||||
assert fm.state.flow_count()
|
||||
|
||||
f.error = Error("error")
|
||||
@ -673,7 +673,7 @@ class TestFlowMaster:
|
||||
|
||||
fm.start_server_playback(pb, False, [], True, False)
|
||||
q = Queue.Queue()
|
||||
fm.tick(q)
|
||||
fm.tick(q, 0)
|
||||
assert fm.should_exit.is_set()
|
||||
|
||||
fm.stop_server_playback()
|
||||
|
@ -83,7 +83,6 @@ class ProxTestBase(object):
|
||||
no_upstream_cert = False
|
||||
authenticator = None
|
||||
masterclass = TestMaster
|
||||
externalapp = False
|
||||
certforward = False
|
||||
|
||||
@classmethod
|
||||
@ -94,7 +93,7 @@ class ProxTestBase(object):
|
||||
cls.config = ProxyConfig(**cls.get_proxy_config())
|
||||
|
||||
tmaster = cls.masterclass(cls.config)
|
||||
tmaster.start_app(APP_HOST, APP_PORT, cls.externalapp)
|
||||
tmaster.start_app(APP_HOST, APP_PORT)
|
||||
cls.proxy = ProxyThread(tmaster)
|
||||
cls.proxy.start()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user