Skip to content
This repository has been archived by the owner on Mar 13, 2022. It is now read-only.

Commit

Permalink
Merge pull request #152 from sergei-maertens/master
Browse files Browse the repository at this point in the history
Refs. #151 -- detect binary payloads and send the correct opcode
  • Loading branch information
k8s-ci-robot authored Feb 14, 2020
2 parents 7ea5cb4 + 3827074 commit a25f49e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion stream/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,16 @@ def readline_channel(self, channel, timeout=None):

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."""
Expand Down

0 comments on commit a25f49e

Please sign in to comment.