diff --git a/socketio/server.py b/socketio/server.py index a5e2e47..1e8495e 100755 --- a/socketio/server.py +++ b/socketio/server.py @@ -278,6 +278,16 @@ class Server(object): self._trigger_event('disconnect', namespace, sid) self.manager.disconnect(sid, namespace=namespace) + def transport(self, sid): + """Return the name of the transport used by the client. + + The two possible values returned by this function are ``'polling'`` + and ``'websocket'``. + + :param sid: The session of the client. + """ + return self.eio.transport(sid) + def handle_request(self, environ, start_response): """Handle an HTTP request from the client. diff --git a/tests/test_server.py b/tests/test_server.py index d410362..8e3a868 100755 --- a/tests/test_server.py +++ b/tests/test_server.py @@ -144,6 +144,13 @@ class TestServer(unittest.TestCase): s._emit_internal('123', u'my event', b'my binary data') self.assertEqual(s.eio.send.call_count, 2) + def test_transport(self, eio): + s = server.Server() + s.eio.transport = mock.MagicMock(return_value='polling') + s._handle_eio_connect('foo', 'environ') + self.assertEqual(s.transport('foo'), 'polling') + s.eio.transport.assert_called_once_with('foo') + def test_handle_connect(self, eio): mgr = mock.MagicMock() s = server.Server(client_manager_class=mgr)