3 from mod_pywebsocket
import common
6 def web_socket_do_extra_handshake(request
):
10 def web_socket_transfer_data(request
):
11 match
= re
.search(r
'\?case=(\d+_\d+)$', request
.ws_resource
)
13 msgutil
.send_message(request
, 'FAIL: Query value is incorrect or missing')
16 payload_length
, extended_length
= (match
.group(1)).split('_', 1)
17 payload_length
= int(payload_length
)
18 extended_length
= int(extended_length
)
20 # pywebsocket refuses to create a frame with error encode length.
21 # Thus, we need to build a frame manually.
22 header
= chr(0x80 | common
.OPCODE_TEXT
) # 0x80 is for "fin" bit.
23 # No Mask and two bytes extended payload length.
24 header
+= chr(payload_length
)
25 if payload_length
== 126:
26 header
+= struct
.pack('!H', extended_length
)
27 elif payload_length
== 127:
28 header
+= struct
.pack('!Q', extended_length
)
30 msgutil
.send_message(request
, 'FAIL: Query value is incorrect or missing')
32 request
.connection
.write(header
)
33 request
.connection
.write('X' * extended_length
)