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 a6adffc commit 19c847d
Show file tree
Hide file tree
Showing 2 changed files with 11 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`.
12 changes: 10 additions & 2 deletions aiohttp/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sys
import traceback
import warnings
import zlib
from contextlib import suppress
from types import TracebackType
from typing import (
Expand Down Expand Up @@ -1005,7 +1006,9 @@ 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 +1039,12 @@ 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 19c847d

Please sign in to comment.