summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOnno Kortmann <onno@gmx.net>2021-04-01 22:24:47 +0200
committerSergey Shepelev <temotor@gmail.com>2021-08-16 00:42:41 +0300
commitc6c350eaa9eb819c6bcabe25113464aed75b9cf5 (patch)
tree147e622ee993e5f508f751f77a51d0b068301449
parentedea63b4184fa7df8c0bd740ac59ec5294eca7b5 (diff)
downloadeventlet-c6c350eaa9eb819c6bcabe25113464aed75b9cf5.tar.gz
websocket: Do not send compressed control frames
This disables compression for the control frames sent by the websocket. As per RFC 7692, Section 6.1: An endpoint MUST NOT set the "Per-Message Compressed" bit of control frames and non-first fragments of a data message.
-rw-r--r--eventlet/websocket.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/eventlet/websocket.py b/eventlet/websocket.py
index 245993d..01245b8 100644
--- a/eventlet/websocket.py
+++ b/eventlet/websocket.py
@@ -766,7 +766,17 @@ class RFC6455WebSocket(WebSocket):
compress_bit = 0
compressor = self._get_permessage_deflate_enc()
- if message and compressor:
+ # Control frames are identified by opcodes where the most significant
+ # bit of the opcode is 1. Currently defined opcodes for control frames
+ # include 0x8 (Close), 0x9 (Ping), and 0xA (Pong). Opcodes 0xB-0xF are
+ # reserved for further control frames yet to be defined.
+ # https://datatracker.ietf.org/doc/html/rfc6455#section-5.5
+ is_control_frame = (control_code or 0) & 8
+ # An endpoint MUST NOT set the "Per-Message Compressed" bit of control
+ # frames and non-first fragments of a data message. An endpoint
+ # receiving such a frame MUST _Fail the WebSocket Connection_.
+ # https://datatracker.ietf.org/doc/html/rfc7692#section-6.1
+ if message and compressor and not is_control_frame:
message = compressor.compress(message)
message += compressor.flush(zlib.Z_SYNC_FLUSH)
assert message[-4:] == b"\x00\x00\xff\xff"