2014-12-29 14:43:40 +03:00
|
|
|
from mod_pywebsocket import msgutil
|
|
|
|
from mod_pywebsocket import common
|
|
|
|
|
2020-08-31 17:42:21 +03:00
|
|
|
|
2014-12-29 14:43:40 +03:00
|
|
|
def web_socket_do_extra_handshake(request):
|
2020-08-31 17:42:21 +03:00
|
|
|
deflate_removed = False
|
|
|
|
|
|
|
|
if request.ws_extension_processors is not None:
|
|
|
|
for extension_processor in request.ws_extension_processors:
|
|
|
|
if extension_processor.name() == "deflate":
|
|
|
|
request.ws_extension_processors.remove(extension_processor)
|
|
|
|
deflate_removed = True
|
2014-12-29 14:43:40 +03:00
|
|
|
|
2020-08-31 17:42:21 +03:00
|
|
|
if deflate_removed is False:
|
|
|
|
raise ValueError("deflate extension processor not found")
|
2014-12-29 14:43:40 +03:00
|
|
|
|
|
|
|
|
|
|
|
def web_socket_transfer_data(request):
|
2020-08-31 17:42:21 +03:00
|
|
|
while True:
|
|
|
|
rcvd = msgutil.receive_message(request)
|
|
|
|
opcode = request.ws_stream.get_last_received_opcode()
|
|
|
|
if opcode == common.OPCODE_BINARY:
|
|
|
|
msgutil.send_message(request, rcvd, binary=True)
|
|
|
|
elif opcode == common.OPCODE_TEXT:
|
|
|
|
msgutil.send_message(request, rcvd)
|