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