2012-04-23 21:43:14 +00:00
|
|
|
#!/usr/bin/env python
|
2012-04-24 02:58:18 +00:00
|
|
|
"""
|
|
|
|
This example shows how to graft a WSGI app onto mitmproxy. In this
|
|
|
|
instance, we're using the Bottle framework (http://bottlepy.org/) to expose
|
|
|
|
a single simplest-possible page.
|
|
|
|
"""
|
2012-04-23 21:43:14 +00:00
|
|
|
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:
|
2013-03-13 20:19:43 +00:00
|
|
|
r.reply()
|
2012-04-23 21:43:14 +00:00
|
|
|
return f
|
|
|
|
|
|
|
|
def handle_response(self, r):
|
|
|
|
f = flow.FlowMaster.handle_response(self, r)
|
|
|
|
if f:
|
2013-03-13 20:19:43 +00:00
|
|
|
r.reply()
|
2012-04-23 21:43:14 +00:00
|
|
|
print f
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
|
|
config = proxy.ProxyConfig(
|
|
|
|
cacert = os.path.expanduser("~/.mitmproxy/mitmproxy-ca.pem")
|
|
|
|
)
|
|
|
|
state = flow.State()
|
|
|
|
server = proxy.ProxyServer(config, 8080)
|
2012-04-24 02:58:18 +00:00
|
|
|
# Register the app using the magic domain "proxapp" on port 80. Requests to
|
|
|
|
# this domain and port combination will now be routed to the WSGI app instance.
|
2012-04-23 21:43:14 +00:00
|
|
|
server.apps.add(bottle.app(), "proxapp", 80)
|
|
|
|
m = MyMaster(server, state)
|
|
|
|
m.run()
|
|
|
|
|