diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-06-26 14:49:23 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-06-26 14:49:23 +1200 |
commit | 658c9c0446591e41d6ebdb223c62c00342b83206 (patch) | |
tree | 8de0be65b0798b2d8bee424210a5fe4a6272886f /netlib | |
parent | ccf2603ddc9c832f9533eeb3c4ffbbd685b00057 (diff) | |
download | mitmproxy-658c9c0446591e41d6ebdb223c62c00342b83206.tar.gz mitmproxy-658c9c0446591e41d6ebdb223c62c00342b83206.tar.bz2 mitmproxy-658c9c0446591e41d6ebdb223c62c00342b83206.zip |
Hunt down a tricky WSGI socket hang.
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/tcp.py | 12 | ||||
-rw-r--r-- | netlib/wsgi.py | 3 |
2 files changed, 11 insertions, 4 deletions
diff --git a/netlib/tcp.py b/netlib/tcp.py index c8ffefdf..aa923fdd 100644 --- a/netlib/tcp.py +++ b/netlib/tcp.py @@ -61,7 +61,10 @@ class TCPClient: if sni: self.connection.set_tlsext_host_name(sni) self.connection.set_connect_state() - self.connection.do_handshake() + try: + self.connection.do_handshake() + except SSL.Error, v: + raise NetLibError("SSL handshake error: %s"%str(v)) self.cert = self.connection.get_peer_certificate() self.rfile = FileLike(self.connection) self.wfile = FileLike(self.connection) @@ -82,7 +85,7 @@ class BaseHandler: The instantiator is expected to call the handle() and finish() methods. """ rbufsize = -1 - wbufsize = 0 + wbufsize = -1 def __init__(self, connection, client_address, server): self.connection = connection self.rfile = self.connection.makefile('rb', self.rbufsize) @@ -100,7 +103,10 @@ class BaseHandler: self.connection = SSL.Connection(ctx, self.connection) self.connection.set_accept_state() # SNI callback happens during do_handshake() - self.connection.do_handshake() + try: + self.connection.do_handshake() + except SSL.Error, v: + raise NetLibError("SSL handshake error: %s"%str(v)) self.rfile = FileLike(self.connection) self.wfile = FileLike(self.connection) diff --git a/netlib/wsgi.py b/netlib/wsgi.py index 755bea5a..6fe6b6b3 100644 --- a/netlib/wsgi.py +++ b/netlib/wsgi.py @@ -104,7 +104,8 @@ class WSGIAdaptor: soc.write(str(h)) soc.write("\r\n") state["headers_sent"] = True - soc.write(data) + if data: + soc.write(data) soc.flush() def start_response(status, headers, exc_info=None): |