Skip to content

Commit

Permalink
Use text/plain content type for base64 encoded responses
Browse files Browse the repository at this point in the history
Fixes #33
  • Loading branch information
miguelgrinberg committed Jan 23, 2017
1 parent e0541bc commit 297ff98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,10 @@ def _ok(self, packets=None, headers=None, b64=False):
if packets is not None:
if headers is None:
headers = []
headers += [('Content-Type', 'application/octet-stream')]
if b64:
headers += [('Content-Type', 'text/plain; charset=UTF-8')]
else:
headers += [('Content-Type', 'application/octet-stream')]
return {'status': '200 OK',
'headers': headers,
'response': payload.Payload(packets=packets).encode(b64)}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ def test_connect(self):
self.assertEqual(len(s.sockets), 1)
self.assertEqual(start_response.call_count, 1)
self.assertEqual(start_response.call_args[0][0], '200 OK')
self.assertIn(('Content-Type', 'application/octet-stream'),
start_response.call_args[0][1])
self.assertEqual(len(r), 1)
packets = payload.Payload(encoded_payload=r[0]).packets
self.assertEqual(len(packets), 1)
Expand All @@ -348,6 +350,8 @@ def test_connect_b64_with_1(self):
start_response = mock.MagicMock()
s.handle_request(environ, start_response)
self.assertTrue(start_response.call_args[0][0], '200 OK')
self.assertIn(('Content-Type', 'text/plain; charset=UTF-8'),
start_response.call_args[0][1])
s.send('1', b'\x00\x01\x02', binary=True)
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=1&b64=1'}
r = s.handle_request(environ, start_response)
Expand All @@ -360,6 +364,8 @@ def test_connect_b64_with_true(self):
start_response = mock.MagicMock()
s.handle_request(environ, start_response)
self.assertTrue(start_response.call_args[0][0], '200 OK')
self.assertIn(('Content-Type', 'text/plain; charset=UTF-8'),
start_response.call_args[0][1])
s.send('1', b'\x00\x01\x02', binary=True)
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=1&b64=true'}
r = s.handle_request(environ, start_response)
Expand All @@ -372,6 +378,8 @@ def test_connect_b64_with_0(self):
start_response = mock.MagicMock()
s.handle_request(environ, start_response)
self.assertTrue(start_response.call_args[0][0], '200 OK')
self.assertIn(('Content-Type', 'application/octet-stream'),
start_response.call_args[0][1])
s.send('1', b'\x00\x01\x02', binary=True)
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=1&b64=0'}
r = s.handle_request(environ, start_response)
Expand All @@ -384,6 +392,8 @@ def test_connect_b64_with_false(self):
start_response = mock.MagicMock()
s.handle_request(environ, start_response)
self.assertTrue(start_response.call_args[0][0], '200 OK')
self.assertIn(('Content-Type', 'application/octet-stream'),
start_response.call_args[0][1])
s.send('1', b'\x00\x01\x02', binary=True)
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=1&b64=false'}
r = s.handle_request(environ, start_response)
Expand Down

0 comments on commit 297ff98

Please sign in to comment.