Skip to content

Commit 4cc55e3

Browse files
[PR #9636/42a69afc backport][3.11] Avoid multiple slice calls in the WebSocket reader (#9637)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent e503f7a commit 4cc55e3

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

CHANGES/9636.feature.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9543.feature.rst

aiohttp/_websocket/reader_c.pxd

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ cdef class WebSocketReader:
7474
chunk_size="unsigned int",
7575
chunk_len="unsigned int",
7676
buf_length="unsigned int",
77-
data=bytes,
7877
payload=bytearray,
7978
first_byte="unsigned char",
8079
second_byte="unsigned char",

aiohttp/_websocket/reader_py.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,9 @@ def parse_frame(
243243
if self._state == READ_HEADER:
244244
if buf_length - start_pos < 2:
245245
break
246-
data = buf[start_pos : start_pos + 2]
246+
first_byte = buf[start_pos]
247+
second_byte = buf[start_pos + 1]
247248
start_pos += 2
248-
first_byte = data[0]
249-
second_byte = data[1]
250249

251250
fin = (first_byte >> 7) & 1
252251
rsv1 = (first_byte >> 6) & 1
@@ -360,6 +359,6 @@ def parse_frame(
360359
self._frame_payload = bytearray()
361360
self._state = READ_HEADER
362361

363-
self._tail = buf[start_pos:]
362+
self._tail = buf[start_pos:] if start_pos < buf_length else b""
364363

365364
return frames

0 commit comments

Comments
 (0)