|
8 | 8 | from aiohttp import WSMsgType
|
9 | 9 | from aiohttp._websocket.reader import WebSocketDataQueue
|
10 | 10 | from aiohttp.base_protocol import BaseProtocol
|
| 11 | +from aiohttp.compression_utils import ZLibBackend |
11 | 12 | from aiohttp.http import WebSocketReader, WebSocketWriter
|
12 | 13 |
|
13 | 14 |
|
@@ -86,24 +87,48 @@ async def test_send_text_masked(
|
86 | 87 | writer.transport.write.assert_called_with(b"\x81\x84\rg\xb3fy\x02\xcb\x12") # type: ignore[attr-defined]
|
87 | 88 |
|
88 | 89 |
|
| 90 | +@pytest.mark.usefixtures("parametrize_zlib_backend") |
89 | 91 | async def test_send_compress_text(
|
90 | 92 | protocol: BaseProtocol, transport: asyncio.Transport
|
91 | 93 | ) -> None:
|
| 94 | + compress_obj = ZLibBackend.compressobj(level=ZLibBackend.Z_BEST_SPEED, wbits=-15) |
92 | 95 | writer = WebSocketWriter(protocol, transport, compress=15)
|
| 96 | + |
| 97 | + msg = ( |
| 98 | + compress_obj.compress(b"text") + compress_obj.flush(ZLibBackend.Z_SYNC_FLUSH) |
| 99 | + ).removesuffix(b"\x00\x00\xff\xff") |
93 | 100 | await writer.send_frame(b"text", WSMsgType.TEXT)
|
94 |
| - writer.transport.write.assert_called_with(b"\xc1\x06*I\xad(\x01\x00") # type: ignore[attr-defined] |
| 101 | + writer.transport.write.assert_called_with( # type: ignore[attr-defined] |
| 102 | + b"\xc1" + len(msg).to_bytes(1, "big") + msg |
| 103 | + ) |
| 104 | + |
| 105 | + msg = ( |
| 106 | + compress_obj.compress(b"text") + compress_obj.flush(ZLibBackend.Z_SYNC_FLUSH) |
| 107 | + ).removesuffix(b"\x00\x00\xff\xff") |
95 | 108 | await writer.send_frame(b"text", WSMsgType.TEXT)
|
96 |
| - writer.transport.write.assert_called_with(b"\xc1\x05*\x01b\x00\x00") # type: ignore[attr-defined] |
| 109 | + writer.transport.write.assert_called_with( # type: ignore[attr-defined] |
| 110 | + b"\xc1" + len(msg).to_bytes(1, "big") + msg |
| 111 | + ) |
97 | 112 |
|
98 | 113 |
|
| 114 | +@pytest.mark.usefixtures("parametrize_zlib_backend") |
99 | 115 | async def test_send_compress_text_notakeover(
|
100 | 116 | protocol: BaseProtocol, transport: asyncio.Transport
|
101 | 117 | ) -> None:
|
| 118 | + compress_obj = ZLibBackend.compressobj(level=ZLibBackend.Z_BEST_SPEED, wbits=-15) |
102 | 119 | writer = WebSocketWriter(protocol, transport, compress=15, notakeover=True)
|
| 120 | + |
| 121 | + msg = ( |
| 122 | + compress_obj.compress(b"text") + compress_obj.flush(ZLibBackend.Z_FULL_FLUSH) |
| 123 | + ).removesuffix(b"\x00\x00\xff\xff") |
103 | 124 | await writer.send_frame(b"text", WSMsgType.TEXT)
|
104 |
| - writer.transport.write.assert_called_with(b"\xc1\x06*I\xad(\x01\x00") # type: ignore[attr-defined] |
| 125 | + writer.transport.write.assert_called_with( # type: ignore[attr-defined] |
| 126 | + b"\xc1" + len(msg).to_bytes(1, "big") + msg |
| 127 | + ) |
105 | 128 | await writer.send_frame(b"text", WSMsgType.TEXT)
|
106 |
| - writer.transport.write.assert_called_with(b"\xc1\x06*I\xad(\x01\x00") # type: ignore[attr-defined] |
| 129 | + writer.transport.write.assert_called_with( # type: ignore[attr-defined] |
| 130 | + b"\xc1" + len(msg).to_bytes(1, "big") + msg |
| 131 | + ) |
107 | 132 |
|
108 | 133 |
|
109 | 134 | async def test_send_compress_text_per_message(
|
|
0 commit comments