From 1d09a558a76042f79bf7a46880d411e0add1494e Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Wed, 11 Jul 2012 07:16:06 +1200 Subject: Fix a subtle termination condition when there's an error in a WSGI app. --- libmproxy/proxy.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 0d1ad692..0a2aa922 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -158,7 +158,10 @@ class ProxyHandler(tcp.BaseHandler): app = self.server.apps.get(request) if app: - app.serve(request, self.wfile) + err = app.serve(request, self.wfile) + self.log(cc, "Error in wsgi app.", err.split("\n")) + if err: + return else: request = request._send(self.mqueue) if request is None: @@ -234,7 +237,10 @@ class ProxyHandler(tcp.BaseHandler): else: sans = [] if not self.config.no_upstream_cert: - cert = certutils.get_remote_cert(host, port, sni) + try: + cert = certutils.get_remote_cert(host, port, sni) + except tcp.NetLibError, v: + raise ProxyError(502, "Unable to get remote cert: %s"%str(v)) sans = cert.altnames host = cert.cn.decode("utf8").encode("idna") ret = certutils.dummy_cert(self.config.certdir, self.config.cacert, host, sans) -- cgit v1.2.3