Skip to content

Commit

Permalink
[PR #9636/42a69afc backport][3.11] Avoid multiple slice calls in the …
Browse files Browse the repository at this point in the history
…WebSocket reader (#9637)

Co-authored-by: J. Nick Koston <[email protected]>
  • Loading branch information
patchback[bot] and bdraco authored Nov 3, 2024
1 parent e503f7a commit 4cc55e3
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES/9636.feature.rst
1 change: 0 additions & 1 deletion aiohttp/_websocket/reader_c.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ cdef class WebSocketReader:
chunk_size="unsigned int",
chunk_len="unsigned int",
buf_length="unsigned int",
data=bytes,
payload=bytearray,
first_byte="unsigned char",
second_byte="unsigned char",
Expand Down
7 changes: 3 additions & 4 deletions aiohttp/_websocket/reader_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,9 @@ def parse_frame(
if self._state == READ_HEADER:
if buf_length - start_pos < 2:
break
data = buf[start_pos : start_pos + 2]
first_byte = buf[start_pos]
second_byte = buf[start_pos + 1]
start_pos += 2
first_byte = data[0]
second_byte = data[1]

fin = (first_byte >> 7) & 1
rsv1 = (first_byte >> 6) & 1
Expand Down Expand Up @@ -360,6 +359,6 @@ def parse_frame(
self._frame_payload = bytearray()
self._state = READ_HEADER

self._tail = buf[start_pos:]
self._tail = buf[start_pos:] if start_pos < buf_length else b""

return frames

0 comments on commit 4cc55e3

Please sign in to comment.