Merge pull request #152 from sergei-maertens/master

Refs. #151 -- detect binary payloads and send the correct opcode
This commit is contained in:
Kubernetes Prow Robot 2020-02-13 17:08:17 -08:00 committed by GitHub
commit a25f49eb41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,7 +133,16 @@ class WSClient:
def write_channel(self, channel, data):
"""Write data to a channel."""
self.sock.send(chr(channel) + data)
# check if we're writing binary data or not
binary = six.PY3 and type(data) == six.binary_type
opcode = ABNF.OPCODE_BINARY if binary else ABNF.OPCODE_TEXT
channel_prefix = chr(channel)
if binary:
channel_prefix = six.binary_type(channel_prefix, "ascii")
payload = channel_prefix + data
self.sock.send(payload, opcode=opcode)
def peek_stdout(self, timeout=0):
"""Same as peek_channel with channel=1."""