mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
c8d2b2594b
This commit adds: - A WSGI App adapter for mitmproxy - An app registry in the proxy instance that lets us link WSGI apps with (hostname, port) combinations. - Fixes for a number of bugs discovered while creating this feature.
42 lines
833 B
Python
Executable File
42 lines
833 B
Python
Executable File
#!/usr/bin/env python
|
|
import bottle
|
|
import os
|
|
from libmproxy import proxy, flow
|
|
|
|
|
|
@bottle.route('/')
|
|
def index():
|
|
return 'Hi!'
|
|
|
|
|
|
class MyMaster(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._ack()
|
|
return f
|
|
|
|
def handle_response(self, r):
|
|
f = flow.FlowMaster.handle_response(self, r)
|
|
if f:
|
|
r._ack()
|
|
print f
|
|
return f
|
|
|
|
|
|
config = proxy.ProxyConfig(
|
|
cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
|
|
)
|
|
state = flow.State()
|
|
server = proxy.ProxyServer(config, 8080)
|
|
server.apps.add(bottle.app(), "proxapp", 80)
|
|
m = MyMaster(server, state)
|
|
m.run()
|
|
|