diff --git a/src/waitress/task.py b/src/waitress/task.py index 620bbdf6..36fb133a 100644 --- a/src/waitress/task.py +++ b/src/waitress/task.py @@ -567,6 +567,10 @@ def get_environment(self): # channel_request_lookahead larger than 0. environ["waitress.client_disconnected"] = self.channel.check_client_disconnected + # Insert the raw socket object into the environment that allows the + # application to upgrade to WebSocket communication. + environ["waitress.socket"] = self.channel.socket + # cache the environ for this request self.environ = environ return environ diff --git a/tests/test_task.py b/tests/test_task.py index 278ab538..8ff4f409 100644 --- a/tests/test_task.py +++ b/tests/test_task.py @@ -1,4 +1,5 @@ import io +import socket import unittest @@ -804,6 +805,7 @@ def test_get_environment_values(self): "SERVER_PROTOCOL", "SERVER_SOFTWARE", "waitress.client_disconnected", + "waitress.socket", "wsgi.errors", "wsgi.file_wrapper", "wsgi.input", @@ -960,6 +962,7 @@ class DummyChannel: adj = DummyAdj() creation_time = 0 addr = ("127.0.0.1", 39830) + socket = socket.socket() def check_client_disconnected(self): # For now, until we have tests handling this feature