Skip to content

Commit

Permalink
Added transport() method
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Sep 2, 2015
1 parent cfff11f commit f3aeeb5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ def disconnect(self, sid=None):
client.close()
self.sockets = {}

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 'websocket' if self._get_socket(sid).upgraded else 'polling'

def handle_request(self, environ, start_response):
"""Handle an HTTP request from the client.
Expand Down
9 changes: 9 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,15 @@ def test_upgrades(self):
s.sockets['foo'].upgraded = True
self.assertEqual(s._upgrades('foo'), [])

def test_transport(self):
s = server.Server()
s.sockets['foo'] = self._get_mock_socket()
s.sockets['foo'].upgraded = False
s.sockets['bar'] = self._get_mock_socket()
s.sockets['bar'].upgraded = True
self.assertEqual(s.transport('foo'), 'polling')
self.assertEqual(s.transport('bar'), 'websocket')

def test_bad_session(self):
s = server.Server()
s.sockets['foo'] = 'client'
Expand Down

0 comments on commit f3aeeb5

Please sign in to comment.