Skip to content

Commit

Permalink
Correctly end eventlet's websocket connection
Browse files Browse the repository at this point in the history
See miguelgrinberg/Flask-SocketIO#167 for the problem this fixes.
  • Loading branch information
miguelgrinberg committed Nov 4, 2015
1 parent ab94e19 commit fef4b47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
7 changes: 6 additions & 1 deletion engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,10 @@ def handle_request(self, environ, start_response):
try:
packets = socket.handle_get_request(
environ, start_response)
r = self._ok(packets, b64=b64)
if isinstance(packets, list):
r = self._ok(packets, b64=b64)
else:
r = packets
except IOError:
del self.sockets[sid]
r = self._bad_request()
Expand All @@ -242,6 +245,8 @@ def handle_request(self, environ, start_response):
else:
self.logger.warning('Method %s not supported', method)
r = self._method_not_found()
if not isinstance(r, dict):
return r
if self.http_compression and \
len(r['response']) >= self.compression_threshold:
encodings = [e.split(';')[0].strip() for e in
Expand Down
9 changes: 9 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,15 @@ def test_get_request(self):
self.assertEqual(len(packets), 1)
self.assertEqual(packets[0].packet_type, packet.MESSAGE)

def test_get_request_custom_response(self):
s = server.Server()
mock_socket = self._get_mock_socket()
mock_socket.handle_get_request = mock.MagicMock(side_effect=['resp'])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo'}
start_response = mock.MagicMock()
self.assertEqual(s.handle_request(environ, start_response), 'resp')

def test_get_request_error(self):
s = server.Server()
mock_socket = self._get_mock_socket()
Expand Down

0 comments on commit fef4b47

Please sign in to comment.