From a608db52d74ef32c320fc3f8fe90f3999a316464 Mon Sep 17 00:00:00 2001 From: cce Date: Sun, 5 Mar 2006 18:10:49 +0000 Subject: There are class of unavoidable socket errors that occur when users click STOP or close their browsers during a SSL connection; unfortunately pyOpenSSL didn't subclass socket.error for these classes -- so we put in a work-around. --- paste/httpserver.py | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'paste/httpserver.py') diff --git a/paste/httpserver.py b/paste/httpserver.py index 0930ced..fb9f793 100755 --- a/paste/httpserver.py +++ b/paste/httpserver.py @@ -226,22 +226,6 @@ class WSGIHandlerMixin: self.wsgi_write_chunk("Internal Server Error\n") raise -class WSGIHandler(WSGIHandlerMixin, BaseHTTPRequestHandler): - """ - A WSGI handler that overrides POST, GET and HEAD to delegate - requests to the server's ``wsgi_application``. - """ - server_version = 'PasteWSGIServer/' + __version__ - do_POST = do_GET = do_HEAD = do_DELETE = do_PUT = do_TRACE = \ - WSGIHandlerMixin.wsgi_execute - - def handle(self): - # don't bother logging disconnects while handling a request - try: - BaseHTTPRequestHandler.handle(self) - except socket.error, exce: - self.wsgi_connection_drop(exce) - # # SSL Functionality # @@ -250,10 +234,12 @@ class WSGIHandler(WSGIHandlerMixin, BaseHTTPRequestHandler): # try: from OpenSSL import SSL + SocketErrors = (socket.error, SSL.ZeroReturnError, SSL.SysCallError) except ImportError: # Do not require pyOpenSSL to be installed, but disable SSL # functionality in that case. SSL = None + SocketErrors = (socket.error,) class SecureHTTPServer(HTTPServer): def __init__(self, server_address, RequestHandlerClass, ssl_context=None): @@ -306,6 +292,22 @@ else: conn = _ConnFixer(conn) return (conn,info) +class WSGIHandler(WSGIHandlerMixin, BaseHTTPRequestHandler): + """ + A WSGI handler that overrides POST, GET and HEAD to delegate + requests to the server's ``wsgi_application``. + """ + server_version = 'PasteWSGIServer/' + __version__ + do_POST = do_GET = do_HEAD = do_DELETE = do_PUT = do_TRACE = \ + WSGIHandlerMixin.wsgi_execute + + def handle(self): + # don't bother logging disconnects while handling a request + try: + BaseHTTPRequestHandler.handle(self) + except SocketErrors, exce: + self.wsgi_connection_drop(exce) + class WSGIServer(ThreadingMixIn, SecureHTTPServer): daemon_threads = False -- cgit v1.2.1