Skip to content

Commit

Permalink
removed transfer-encoding header from ws aio-libs#3798
Browse files Browse the repository at this point in the history
  • Loading branch information
nebularazer committed May 24, 2019
1 parent d73e5eb commit d738a88
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGES/3798.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Removed `Transfer-Encoding: chunked` header from websocket responses to be compatible with more http proxy servers.
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ Eugene Naydenov
Eugene Tolmachev
Evert Lammerts
FichteFoll
Florian Scheffler
Frederik Gladhorn
Frederik Peter Aalund
Gabriel Tremblay
Expand Down
14 changes: 12 additions & 2 deletions aiohttp/web_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,21 +371,31 @@ async def _start(self, request: 'BaseRequest') -> AbstractStreamWriter:
if self._compression:
await self._start_compression(request)

if all([
'websocket' == headers.get(hdrs.UPGRADE, '').lower().strip(),
'upgrade' == headers.get(hdrs.CONNECTION, '').lower()
]):
websocket_response = True
else:
websocket_response = False

if self._chunked:
if version != HttpVersion11:
raise RuntimeError(
"Using chunked encoding is forbidden "
"for HTTP/{0.major}.{0.minor}".format(request.version))
writer.enable_chunking()
headers[hdrs.TRANSFER_ENCODING] = 'chunked'
if websocket_response is False:
headers[hdrs.TRANSFER_ENCODING] = 'chunked'
if hdrs.CONTENT_LENGTH in headers:
del headers[hdrs.CONTENT_LENGTH]
elif self._length_check:
writer.length = self.content_length
if writer.length is None:
if version >= HttpVersion11:
writer.enable_chunking()
headers[hdrs.TRANSFER_ENCODING] = 'chunked'
if websocket_response is False:
headers[hdrs.TRANSFER_ENCODING] = 'chunked'
if hdrs.CONTENT_LENGTH in headers:
del headers[hdrs.CONTENT_LENGTH]
else:
Expand Down
1 change: 0 additions & 1 deletion aiohttp/web_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ def _handshake(self, request: BaseRequest) -> Tuple['CIMultiDict[str]',
response_headers = CIMultiDict( # type: ignore
{hdrs.UPGRADE: 'websocket',
hdrs.CONNECTION: 'upgrade',
hdrs.TRANSFER_ENCODING: 'chunked',
hdrs.SEC_WEBSOCKET_ACCEPT: accept_val})

notakeover = False
Expand Down

0 comments on commit d738a88

Please sign in to comment.