Skip to content

Commit

Permalink
Added transport method to server class
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Sep 2, 2015
1 parent a1e232f commit 37cd746
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions socketio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ def disconnect(self, sid, namespace=None):
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.
Expand Down
7 changes: 7 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def test_emit_internal_binary(self, eio):
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)
Expand Down

0 comments on commit 37cd746

Please sign in to comment.