xpra icon
Bug tracker and wiki

This bug tracker and wiki are being discontinued
please use https://github.com/Xpra-org/xpra instead.


Ticket #1134: nojoin.patch

File nojoin.patch, 3.3 KB (added by Antoine Martin, 6 years ago)

first version: just never join the headers and packet data

  • tests/test_websocket.py

    diff --git a/tests/test_websocket.py b/tests/test_websocket.py
    index 9d538db..58b38ef 100644
    a b class HyBiEncodeDecodeTestCase(unittest.TestCase): 
    409409
    410410    def test_encode_hybi_basic(self):
    411411        res = websocket.WebSocketRequestHandler.encode_hybi(b'Hello', 0x1)
    412         expected = (b'\x81\x05\x48\x65\x6c\x6c\x6f', 2, 0)
     412        expected_header = (b'\x81\x05')
     413        expected_data = (b'\x48\x65\x6c\x6c\x6f')
    413414
    414         self.assertEqual(res, expected)
     415        self.assertEqual(res[0], expected_header)
     416        self.assertEqual(res[1], expected_data)
    415417
    416418    def test_strict_mode_refuses_unmasked_client_frames(self):
    417419        buf = b'\x81\x05\x48\x65\x6c\x6c\x6f'
  • websockify/websocket.py

    diff --git a/websockify/websocket.py b/websockify/websocket.py
    index 16e1dc4..a954813 100644
    a b class WebSocketRequestHandler(SimpleHTTPRequestHandler): 
    178178
    179179        #self.msg("Encoded: %s", repr(header + buf))
    180180
    181         return header + buf, len(header), 0
     181        return [header, buf]
    182182
    183183    @staticmethod
    184184    def decode_hybi(buf, base64=False, logger=None, strict=True):
    class WebSocketRequestHandler(SimpleHTTPRequestHandler): 
    311311        if bufs:
    312312            for buf in bufs:
    313313                if self.base64:
    314                     encbuf, lenhead, lentail = self.encode_hybi(buf, opcode=1, base64=True)
     314                    encbufs = self.encode_hybi(buf, opcode=1, base64=True)
    315315                else:
    316                     encbuf, lenhead, lentail = self.encode_hybi(buf, opcode=2, base64=False)
     316                    encbufs = self.encode_hybi(buf, opcode=2, base64=False)
    317317
    318318                if self.rec:
    319319                    self.rec.write("%s,\n" %
    320                             repr("{%s{" % tdelta
    321                                 + encbuf[lenhead:len(encbuf)-lentail]))
     320                            repr("{%s{" % tdelta + encbufs[1]))
    322321
    323                 self.send_parts.append(encbuf)
     322                for encbuf in encbufs:
     323                    self.send_parts.append(encbuf)
    324324
    325325        while self.send_parts:
    326326            # Send pending frames
    class WebSocketRequestHandler(SimpleHTTPRequestHandler): 
    412412        """ Send a WebSocket orderly close frame. """
    413413
    414414        msg = pack(">H%ds" % len(reason), code, s2b(reason))
    415         buf, h, t = self.encode_hybi(msg, opcode=0x08, base64=False)
    416         self.request.send(buf)
     415        bufs = self.encode_hybi(msg, opcode=0x08, base64=False)
     416        for buf in bufs:
     417            self.request.send(buf)
    417418
    418419    def send_pong(self, data=''):
    419420        """ Send a WebSocket pong frame. """
    420         buf, h, t = self.encode_hybi(s2b(data), opcode=0x0A, base64=False)
    421         self.request.send(buf)
     421        bufs = self.encode_hybi(s2b(data), opcode=0x0A, base64=False)
     422        for buf in bufs:
     423            self.request.send(buf)
    422424
    423425    def send_ping(self, data=''):
    424426        """ Send a WebSocket ping frame. """
    425         buf, h, t = self.encode_hybi(s2b(data), opcode=0x09, base64=False)
    426         self.request.send(buf)
     427        bufs = self.encode_hybi(s2b(data), opcode=0x09, base64=False)
     428        for buf in bufs:
     429            self.request.send(buf)
    427430
    428431    def do_websocket_handshake(self):
    429432        h = self.headers