Delay SSL handshake

This commit is contained in:
Unrud 2018-09-04 03:33:43 +02:00
parent 17127d97a6
commit 49d35cf618

View File

@ -87,9 +87,12 @@ class ParallelHTTPServer(ParallelizationMixIn,
socket_.settimeout(self.client_timeout) socket_.settimeout(self.client_timeout)
return socket_, address return socket_, address
def finish_request_locked(self, request, client_address):
return super().finish_request(request, client_address)
def finish_request(self, request, client_address): def finish_request(self, request, client_address):
with self.connections_guard: with self.connections_guard:
return super().finish_request(request, client_address) return self.finish_request_locked(request, client_address)
def handle_error(self, request, client_address): def handle_error(self, request, client_address):
if issubclass(sys.exc_info()[0], socket.timeout): if issubclass(sys.exc_info()[0], socket.timeout):
@ -131,20 +134,21 @@ class ParallelHTTPSServer(ParallelHTTPServer):
raise raise
def finish_request(self, request, client_address): def finish_request(self, request, client_address):
try: with self.connections_guard:
try: try:
request.do_handshake() try:
except socket.timeout: request.do_handshake()
raise except socket.timeout:
except Exception as e: raise
raise RuntimeError("SSL handshake failed: %s" % e) from e except Exception as e:
except Exception: raise RuntimeError("SSL handshake failed: %s" % e) from e
try: except Exception:
self.handle_error(request, client_address) try:
finally: self.handle_error(request, client_address)
self.shutdown_request(request) finally:
return self.shutdown_request(request)
return super().finish_request(request, client_address) return
return super().finish_request_locked(request, client_address)
class ServerHandler(wsgiref.simple_server.ServerHandler): class ServerHandler(wsgiref.simple_server.ServerHandler):