Skip to content

Commit

Permalink
Use correct key name for ACCEPT_ENCODING header
Browse files Browse the repository at this point in the history
Fixes #39
  • Loading branch information
miguelgrinberg committed Feb 22, 2017
1 parent e1b531f commit f1df2e4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion engineio/asyncio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ async def handle_request(self, *args, **kwargs):
if self.http_compression and \
len(r['response']) >= self.compression_threshold:
encodings = [e.split(';')[0].strip() for e in
environ.get('ACCEPT_ENCODING', '').split(',')]
environ.get('HTTP_ACCEPT_ENCODING', '').split(',')]
for encoding in encodings:
if encoding in self.compression_methods:
r['response'] = \
Expand Down
2 changes: 1 addition & 1 deletion engineio/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ def handle_request(self, environ, start_response):
if self.http_compression and \
len(r['response']) >= self.compression_threshold:
encodings = [e.split(';')[0].strip() for e in
environ.get('ACCEPT_ENCODING', '').split(',')]
environ.get('HTTP_ACCEPT_ENCODING', '').split(',')]
for encoding in encodings:
if encoding in self.compression_methods:
r['response'] = \
Expand Down
12 changes: 6 additions & 6 deletions tests/test_asyncio_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def _gzip_decompress(b):
def test_gzip_compression(self, import_module):
a = self.get_async_mock({'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'gzip,deflate'})
'HTTP_ACCEPT_ENCODING': 'gzip,deflate'})
import_module.side_effect = [a]
s = asyncio_server.AsyncServer(compression_threshold=0)
s.sockets['foo'] = mock_socket = self._get_mock_socket()
Expand All @@ -531,7 +531,7 @@ def test_gzip_compression(self, import_module):
def test_deflate_compression(self, import_module):
a = self.get_async_mock({'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'deflate;q=1,gzip'})
'HTTP_ACCEPT_ENCODING': 'deflate;q=1,gzip'})
import_module.side_effect = [a]
s = asyncio_server.AsyncServer(compression_threshold=0)
s.sockets['foo'] = mock_socket = self._get_mock_socket()
Expand All @@ -546,7 +546,7 @@ def test_deflate_compression(self, import_module):
def test_gzip_compression_threshold(self, import_module):
a = self.get_async_mock({'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'gzip'})
'HTTP_ACCEPT_ENCODING': 'gzip'})
import_module.side_effect = [a]
s = asyncio_server.AsyncServer(compression_threshold=1000)
s.sockets['foo'] = mock_socket = self._get_mock_socket()
Expand All @@ -563,7 +563,7 @@ def test_gzip_compression_threshold(self, import_module):
def test_compression_disabled(self, import_module):
a = self.get_async_mock({'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'gzip'})
'HTTP_ACCEPT_ENCODING': 'gzip'})
import_module.side_effect = [a]
s = asyncio_server.AsyncServer(http_compression=False,
compression_threshold=0)
Expand All @@ -581,7 +581,7 @@ def test_compression_disabled(self, import_module):
def test_compression_unknown(self, import_module):
a = self.get_async_mock({'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'rar'})
'HTTP_ACCEPT_ENCODING': 'rar'})
import_module.side_effect = [a]
s = asyncio_server.AsyncServer(compression_threshold=0)
s.sockets['foo'] = mock_socket = self._get_mock_socket()
Expand All @@ -598,7 +598,7 @@ def test_compression_unknown(self, import_module):
def test_compression_no_encoding(self, import_module):
a = self.get_async_mock({'REQUEST_METHOD': 'GET',
'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': ''})
'HTTP_ACCEPT_ENCODING': ''})
import_module.side_effect = [a]
s = asyncio_server.AsyncServer(compression_threshold=0)
s.sockets['foo'] = mock_socket = self._get_mock_socket()
Expand Down
12 changes: 6 additions & 6 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ def test_gzip_compression(self):
packet.Packet(packet.MESSAGE, data='hello')])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'gzip,deflate'}
'HTTP_ACCEPT_ENCODING': 'gzip,deflate'}
start_response = mock.MagicMock()
r = s.handle_request(environ, start_response)
self.assertIn(('Content-Encoding', 'gzip'),
Expand All @@ -643,7 +643,7 @@ def test_deflate_compression(self):
packet.Packet(packet.MESSAGE, data='hello')])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'deflate;q=1,gzip'}
'HTTP_ACCEPT_ENCODING': 'deflate;q=1,gzip'}
start_response = mock.MagicMock()
r = s.handle_request(environ, start_response)
self.assertIn(('Content-Encoding', 'deflate'),
Expand All @@ -657,7 +657,7 @@ def test_gzip_compression_threshold(self):
packet.Packet(packet.MESSAGE, data='hello')])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'gzip'}
'HTTP_ACCEPT_ENCODING': 'gzip'}
start_response = mock.MagicMock()
r = s.handle_request(environ, start_response)
for header, value in start_response.call_args[0][1]:
Expand All @@ -671,7 +671,7 @@ def test_compression_disabled(self):
packet.Packet(packet.MESSAGE, data='hello')])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'gzip'}
'HTTP_ACCEPT_ENCODING': 'gzip'}
start_response = mock.MagicMock()
r = s.handle_request(environ, start_response)
for header, value in start_response.call_args[0][1]:
Expand All @@ -685,7 +685,7 @@ def test_compression_unknown(self):
packet.Packet(packet.MESSAGE, data='hello')])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': 'rar'}
'HTTP_ACCEPT_ENCODING': 'rar'}
start_response = mock.MagicMock()
r = s.handle_request(environ, start_response)
for header, value in start_response.call_args[0][1]:
Expand All @@ -699,7 +699,7 @@ def test_compression_no_encoding(self):
packet.Packet(packet.MESSAGE, data='hello')])
s.sockets['foo'] = mock_socket
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=foo',
'ACCEPT_ENCODING': ''}
'HTTP_ACCEPT_ENCODING': ''}
start_response = mock.MagicMock()
r = s.handle_request(environ, start_response)
for header, value in start_response.call_args[0][1]:
Expand Down

0 comments on commit f1df2e4

Please sign in to comment.