diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-04-24 09:43:14 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-04-24 14:52:29 +1200 |
commit | c8d2b2594bd38d988c387073ac5cfe62cf05122e (patch) | |
tree | bd0bd0bd644bcb7d7b8419c761dde092f6ed662c /examples | |
parent | 51789228beb18194a37fbde153247cb52b20cbf8 (diff) | |
download | mitmproxy-c8d2b2594bd38d988c387073ac5cfe62cf05122e.tar.gz mitmproxy-c8d2b2594bd38d988c387073ac5cfe62cf05122e.tar.bz2 mitmproxy-c8d2b2594bd38d988c387073ac5cfe62cf05122e.zip |
Add a WSGI adapter that lets us serve a WSGI app out of mitmproxy.
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.
Diffstat (limited to 'examples')
-rwxr-xr-x | examples/proxapp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/proxapp b/examples/proxapp new file mode 100755 index 00000000..cb1fd881 --- /dev/null +++ b/examples/proxapp @@ -0,0 +1,41 @@ +#!/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() + |