diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2011-03-12 13:47:37 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2011-03-12 13:47:37 +1300 |
commit | 40e9067b831641820019ea808d6c0099a668a03c (patch) | |
tree | f63278cdfbc4a1b3228f0b574f51952298c2985a /libmproxy | |
parent | 9f16a84a9e771dbbc3314daafaf63449de73d3eb (diff) | |
download | mitmproxy-40e9067b831641820019ea808d6c0099a668a03c.tar.gz mitmproxy-40e9067b831641820019ea808d6c0099a668a03c.tar.bz2 mitmproxy-40e9067b831641820019ea808d6c0099a668a03c.zip |
Handle invalid bind address specifications gracefully.
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/console.py | 2 | ||||
-rw-r--r-- | libmproxy/flow.py | 2 | ||||
-rw-r--r-- | libmproxy/proxy.py | 10 |
3 files changed, 11 insertions, 3 deletions
diff --git a/libmproxy/console.py b/libmproxy/console.py index f63115aa..e9992a0f 100644 --- a/libmproxy/console.py +++ b/libmproxy/console.py @@ -75,8 +75,6 @@ def format_flow(f, focus, extended=False, padding=2): txt.append(("method", "[replay] ")) elif f.modified(): txt.append(("method", "[edited] ")) - if not (f.response or f.error): - txt.append(("text", "waiting for response...")) if f.response: txt.append( diff --git a/libmproxy/flow.py b/libmproxy/flow.py index d555c926..4bcbbb97 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -560,11 +560,13 @@ class FlowWriter: s = json.dumps(d) self.ns.write(s) + class FlowReadError(Exception): @property def strerror(self): return self.args[0] + class FlowReader: def __init__(self, fo): self.fo = fo diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index bff67000..8c9302fe 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -726,14 +726,22 @@ class ProxyHandler(SocketServer.StreamRequestHandler): pass +class ProxyServerError(Exception): pass + ServerBase = SocketServer.ThreadingTCPServer ServerBase.daemon_threads = True # Terminate workers when main thread terminates class ProxyServer(ServerBase): request_queue_size = 20 allow_reuse_address = True def __init__(self, config, port, address=''): + """ + Raises ProxyServerError if there's a startup problem. + """ self.config, self.port, self.address = config, port, address - ServerBase.__init__(self, (address, port), ProxyHandler) + try: + ServerBase.__init__(self, (address, port), ProxyHandler) + except socket.error, v: + raise ProxyServerError('Error starting proxy server: ' + v.strerror) self.masterq = None self.certdir = tempfile.mkdtemp(prefix="mitmproxy") config.certdir = self.certdir |