Skip to content

Commit

Permalink
Support gzip compression in ClientSession._ws_connect() if specifie…
Browse files Browse the repository at this point in the history
…d by server
  • Loading branch information
jakob-keller committed Nov 17, 2024
1 parent e4d48fd commit 98c83e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES/9933.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Provided experimental support for communicating with WebSocket servers that require the `permessage-gzip` extension -- by :user:`jakob-keller`.
6 changes: 4 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ async def _ws_connect(
compress_hdrs = resp.headers.get(hdrs.SEC_WEBSOCKET_EXTENSIONS)
if compress_hdrs:
try:
compress, notakeover = ws_ext_parse(compress_hdrs)
compress, notakeover = ws_ext_parse(compress_hdrs, detect_gzip=True)
except WSHandshakeError as exc:
raise WSServerHandshakeError(
resp.request_info,
Expand Down Expand Up @@ -1036,7 +1036,9 @@ async def _ws_connect(
transport = conn.transport
assert transport is not None
reader = WebSocketDataQueue(conn_proto, 2**16, loop=self._loop)
conn_proto.set_parser(WebSocketReader(reader, max_msg_size), reader)
conn_proto.set_parser(WebSocketReader(
reader, max_msg_size, compress=compress <= zlib.MAX_WBITS or "gzip"
), reader)
writer = WebSocketWriter(
conn_proto,
transport,
Expand Down

0 comments on commit 98c83e4

Please sign in to comment.