コード例 #1
0
 def test_len64(self):
     data = u'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n'.encode(
         'utf-8')
     data += b'\x82\x7f\x00\x00\x00\x00\x00\x00\x00\x04\x00\x01\x02\x03'
     handler = WsHandler()
     parser = ws.WebSocketParser(handler)
     parser.dataReceived(data)
     self.assertEquals(101, handler.code)
     self.assertEquals(2, handler.frame[0])
     self.assertEquals(4, len(handler.frame[1]))
コード例 #2
0
 def test_framing(self):
     data1 = u'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n'.encode(
         'utf-8')
     data1 += b'\x03\x03\x01\x02\x03'
     data2 = b'\x83\x03\x04\x05\x06'
     handler = WsHandler()
     parser = ws.WebSocketParser(handler)
     parser.dataReceived(data1)
     self.assertEquals(None, handler.frame)
     parser.dataReceived(data2)
     self.assertEquals(b'\x01\x02\x03\x04\x05\x06', handler.frame[1])
コード例 #3
0
 def test_masking(self):
     data = u'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n'.encode(
         'utf-8')
     data += b'\x83\x83\x01\x02\x03'
     handler = WsHandler()
     parser = ws.WebSocketParser(handler)
     try:
         parser.dataReceived(data)
         self.fail('Websocket server is not allowed to mask data')
     except ws.WebSocketError:
         pass
コード例 #4
0
 def test_headers(self):
     data = u'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n'.encode(
         'utf-8')
     handler = WsHandler()
     parser = ws.WebSocketParser(handler)
     parser.dataReceived(data)
     self.assertEquals('HTTP/1.1', handler.proto_version)
     self.assertEquals(101, handler.code)
     self.assertEquals(
         [('Upgrade', 'websocket'), ('Connection', 'Upgrade'),
          ('Sec-WebSocket-Accept', 's3pPLMBiTxaQ9kYGzzhZRbK+xOo=')],
         handler.headers)
コード例 #5
0
 def test_len7(self):
     data = u'HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n'.encode(
         'utf-8')
     data += b'\x83\x03\x01\x02\x03'
     #
     handler = WsHandler()
     parser = ws.WebSocketParser(handler)
     parser.dataReceived(data)
     #
     self.assertEquals('HTTP/1.1', handler.proto_version)
     self.assertEquals(101, handler.code)
     self.assertEquals(0x03, handler.frame[0])
     self.assertEquals(b'\x01\x02\x03', handler.frame[1])