mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 02:10:59 +00:00
08895e9ba6
- restructure examples (fix #4031) - remove example dependencies from setup.py, we do not need special dependencies for our supported addons. - unify how we generate docs from code - improve example docs
28 lines
908 B
Python
28 lines
908 B
Python
"""
|
|
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)
|
|
]
|