diff --git a/socketio/server.py b/socketio/server.py index c2c4969..18b2188 100644 --- a/socketio/server.py +++ b/socketio/server.py @@ -534,6 +534,16 @@ class Server(object): """ return self.eio.transport(sid) + def get_environ(self, sid, namespace=None): + """Return the WSGI environ dictionary for a client. + + :param sid: The session of the client. + :param namespace: The Socket.IO namespace. If this argument is omitted + the default namespace is used. + """ + eio_sid = self.manager.eio_sid_from_sid(sid, namespace or '/') + return self.environ.get(eio_sid) + def handle_request(self, environ, start_response): """Handle an HTTP request from the client. diff --git a/tests/common/test_server.py b/tests/common/test_server.py index d8221e3..0732bc3 100644 --- a/tests/common/test_server.py +++ b/tests/common/test_server.py @@ -746,6 +746,14 @@ class TestServer(unittest.TestCase): with pytest.raises(ValueError): s.register_namespace(AsyncNS()) + def test_get_environ(self, eio): + s = server.Server() + s._handle_eio_connect('123', 'environ') + s._handle_eio_message('123', '0') + sid = s.manager.sid_from_eio_sid('123', '/') + assert s.get_environ(sid) == 'environ' + assert s.get_environ('foo') is None + def test_logger(self, eio): s = server.Server(logger=False) assert s.logger.getEffectiveLevel() == logging.ERROR