receive-many-with-backpressure_wsh.py (752B)
1 # Sleep to build backpressure, receive messages, and send back their length. 2 # Used by send-many-64K-messages-with-backpressure.any.js. 3 4 5 import time 6 7 8 def web_socket_do_extra_handshake(request): 9 # Compression will interfere with backpressure, so disable the 10 # permessage-delate extension. 11 request.ws_extension_processors = [] 12 13 14 def web_socket_transfer_data(request): 15 while True: 16 # Don't read the message immediately, so backpressure can build. 17 time.sleep(0.1) 18 line = request.ws_stream.receive_message() 19 if line is None: 20 return 21 # Send back the size of the message as acknowledgement that it was 22 # received. 23 request.ws_stream.send_message(str(len(line)), binary=False)