OLD | NEW |
1 import struct | 1 import struct |
2 | 2 |
3 from mod_pywebsocket import msgutil | 3 from mod_pywebsocket import msgutil |
4 from mod_pywebsocket import stream | 4 from mod_pywebsocket import stream |
5 | 5 |
6 def web_socket_do_extra_handshake(request): | 6 def web_socket_do_extra_handshake(request): |
7 pass | 7 pass |
8 | 8 |
9 | 9 |
10 def web_socket_transfer_data(request): | 10 def web_socket_transfer_data(request): |
11 # Wait for a close frame sent from the client. | 11 # Wait for a close frame sent from the client. |
12 close_frame = request.ws_stream.receive_bytes(6) | 12 close_frame = request.ws_stream.receive_bytes(6) |
13 | 13 |
14 msgutil.send_message(request, 'Client should ignore this message') | 14 msgutil.send_message(request, 'Client should ignore this message') |
15 | 15 |
16 # Send only first two bytes of the received frame. The remaining four bytes
are | 16 # Send only first two bytes of the received frame. The remaining four bytes
are |
17 # "masking key", which changes every time the test runs. | 17 # "masking key", which changes every time the test runs. |
18 data = struct.pack('!H', 1000) + 'close_frame[:2]=%r' % close_frame[:2] | 18 data = struct.pack('!H', 1000) + 'close_frame[:2]=%r' % close_frame[:2] |
19 request.connection.write(stream.create_close_frame(data)) | 19 request.connection.write(stream.create_close_frame(data)) |
20 | 20 |
21 # If the following assertion fails, AssertionError will be raised, | 21 # If the following assertion fails, AssertionError will be raised, |
22 # which will prevent pywebsocket from sending a close frame. | 22 # which will prevent pywebsocket from sending a close frame. |
23 # In this case, the client will fail to finish closing handshake, thus | 23 # In this case, the client will fail to finish closing handshake, thus |
24 # closeEvent.wasClean will become false. | 24 # closeEvent.wasClean will become false. |
25 assert close_frame[:2] == '\x88\x80' | 25 assert close_frame[:2] == '\x88\x80' |
26 | 26 |
27 # Pretend we have received a close frame from the client. | 27 # Pretend we have received a close frame from the client. |
28 # After this function exits, pywebsocket will send a close frame automatical
ly. | 28 # After this function exits, pywebsocket will send a close frame automatical
ly. |
29 request.client_terminated = True | 29 request.client_terminated = True |
OLD | NEW |