Browse Source

Return environ dictionary for a client

pull/599/head
Miguel Grinberg 4 years ago
parent
commit
2e71c22c6d
  1. 10
      socketio/server.py
  2. 8
      tests/common/test_server.py

10
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.

8
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

Loading…
Cancel
Save