diff options
Diffstat (limited to 'testing/web-platform/tests/tools/wptserve/wptserve/server.py')
-rw-r--r-- | testing/web-platform/tests/tools/wptserve/wptserve/server.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/testing/web-platform/tests/tools/wptserve/wptserve/server.py b/testing/web-platform/tests/tools/wptserve/wptserve/server.py index e1772d00b1..8ce36201ee 100644 --- a/testing/web-platform/tests/tools/wptserve/wptserve/server.py +++ b/testing/web-platform/tests/tools/wptserve/wptserve/server.py @@ -130,7 +130,9 @@ class RequestRewriter: class WebTestServer(http.server.ThreadingHTTPServer): allow_reuse_address = True - acceptable_errors = (errno.EPIPE, errno.ECONNABORTED) + # Older versions of Python might throw `OSError: [Errno 0] Error` + # instead of `SSLEOFError`. + acceptable_errors = (errno.EPIPE, errno.ECONNABORTED, 0) request_queue_size = 2000 # Ensure that we don't hang on shutdown waiting for requests @@ -214,14 +216,21 @@ class WebTestServer(http.server.ThreadingHTTPServer): ssl_context.load_cert_chain(keyfile=self.key_file, certfile=self.certificate) ssl_context.set_alpn_protocols(['h2']) self.socket = ssl_context.wrap_socket(self.socket, + do_handshake_on_connect=False, server_side=True) else: ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) ssl_context.load_cert_chain(keyfile=self.key_file, certfile=self.certificate) self.socket = ssl_context.wrap_socket(self.socket, + do_handshake_on_connect=False, server_side=True) + def finish_request(self, request, client_address): + if isinstance(self.socket, ssl.SSLSocket): + request.do_handshake() + super().finish_request(request, client_address) + def handle_error(self, request, client_address): error = sys.exc_info()[1] @@ -229,7 +238,11 @@ class WebTestServer(http.server.ThreadingHTTPServer): isinstance(error.args, tuple) and error.args[0] in self.acceptable_errors) or (isinstance(error, IOError) and - error.errno in self.acceptable_errors)): + error.errno in self.acceptable_errors) or + # `SSLEOFError` and `SSLError` may occur when a client + # (e.g., wptrunner's `TestEnvironment`) tests for connectivity + # but doesn't perform the handshake. + isinstance(error, ssl.SSLEOFError) or isinstance(error, ssl.SSLError)): pass # remote hang up before the result is sent else: msg = traceback.format_exc() |