mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
67885320c0
This commit replaces our WSGI implementation with a new ASGI one, which then uses `asgiref`'s compatibility mode to still support WSGI applications. The ASGI implementation is a bit bare-bone, but good enough for our purposes. The major changes are: - We now support ASGI apps. - Instead of taking connections out of mitmproxy's normal processing, we now just set flow.response and let things continue as usual. This allows users to see responses in mitmproxy, use the response hook to modify app responses, etc. Also important for us, this makes the new implementation work for shenanigans like sans-io.
40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
from mitmproxy.addons import asgiapp
|
|
from mitmproxy.addons.onboardingapp import app
|
|
from mitmproxy import ctx
|
|
|
|
APP_HOST = "mitm.it"
|
|
APP_PORT = 80
|
|
|
|
|
|
class Onboarding(asgiapp.WSGIApp):
|
|
name = "onboarding"
|
|
|
|
def __init__(self):
|
|
super().__init__(app, APP_HOST, APP_PORT)
|
|
|
|
def load(self, loader):
|
|
loader.add_option(
|
|
"onboarding", bool, True,
|
|
"Toggle the mitmproxy onboarding app."
|
|
)
|
|
loader.add_option(
|
|
"onboarding_host", str, APP_HOST,
|
|
"""
|
|
Onboarding app domain. For transparent mode, use an IP when a DNS
|
|
entry for the app domain is not present.
|
|
"""
|
|
)
|
|
loader.add_option(
|
|
"onboarding_port", int, APP_PORT,
|
|
"Port to serve the onboarding app from."
|
|
)
|
|
|
|
def configure(self, updated):
|
|
self.host = ctx.options.onboarding_host
|
|
self.port = ctx.options.onboarding_port
|
|
app.config["CONFDIR"] = ctx.options.confdir
|
|
|
|
def request(self, f):
|
|
if ctx.options.onboarding:
|
|
super().request(f)
|