diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-19 10:42:55 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-19 10:42:55 +1200 |
commit | 7cb242c168501d3f67ddc81dbdc3a96097981e8b (patch) | |
tree | 56878f5a1f48da99b671d906921a2bd032fc88f8 /libmproxy/proxy.py | |
parent | 1b1ccab8b7f88c9e7e6f1d5ae8d6782bc9a1ac2e (diff) | |
download | mitmproxy-7cb242c168501d3f67ddc81dbdc3a96097981e8b.tar.gz mitmproxy-7cb242c168501d3f67ddc81dbdc3a96097981e8b.tar.bz2 mitmproxy-7cb242c168501d3f67ddc81dbdc3a96097981e8b.zip |
Move wsgi to netlib.
Diffstat (limited to 'libmproxy/proxy.py')
-rw-r--r-- | libmproxy/proxy.py | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 04734fcb..0805a63d 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -16,8 +16,8 @@ import sys, os, string, socket, time import shutil, tempfile, threading import optparse, SocketServer from OpenSSL import SSL -from netlib import odict, tcp, protocol -import utils, flow, certutils, version, wsgi +from netlib import odict, tcp, protocol, wsgi +import utils, flow, certutils, version class ProxyError(Exception): @@ -333,7 +333,7 @@ class ProxyServer(tcp.TCPServer): self.masterq = None self.certdir = tempfile.mkdtemp(prefix="mitmproxy") config.certdir = self.certdir - self.apps = wsgi.AppRegistry() + self.apps = AppRegistry() def start_slave(self, klass, masterq): slave = klass(masterq, self) @@ -352,6 +352,24 @@ class ProxyServer(tcp.TCPServer): pass +class AppRegistry: + def __init__(self): + self.apps = {} + + def add(self, app, domain, port): + """ + Add a WSGI app to the registry, to be served for requests to the + specified domain, on the specified port. + """ + self.apps[(domain, port)] = wsgi.WSGIAdaptor(app, domain, port, version.NAMEVERSION) + + def get(self, request): + """ + Returns an WSGIAdaptor instance if request matches an app, or None. + """ + return self.apps.get((request.host, request.port), None) + + class DummyServer: bound = False def __init__(self, config): |