xref: /aosp_15_r20/external/cronet/net/data/websocket/trailing-whitespace_wsh.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker# Copyright 2015 The Chromium Authors
2*6777b538SAndroid Build Coastguard Worker# Use of this source code is governed by a BSD-style license that can be
3*6777b538SAndroid Build Coastguard Worker# found in the LICENSE file.
4*6777b538SAndroid Build Coastguard Worker#
5*6777b538SAndroid Build Coastguard Worker# The purpose of this test is to verify that the WebSocket handshake correctly
6*6777b538SAndroid Build Coastguard Worker# ignores trailing whitespace on response headers.
7*6777b538SAndroid Build Coastguard Worker# It is used by test case WebSocketEndToEndTest.TrailingWhitespace.
8*6777b538SAndroid Build Coastguard Worker
9*6777b538SAndroid Build Coastguard Workerfrom mod_pywebsocket import handshake
10*6777b538SAndroid Build Coastguard Workerfrom mod_pywebsocket.handshake.hybi import compute_accept_from_unicode
11*6777b538SAndroid Build Coastguard Worker
12*6777b538SAndroid Build Coastguard Worker
13*6777b538SAndroid Build Coastguard Workerdef web_socket_do_extra_handshake(request):
14*6777b538SAndroid Build Coastguard Worker  accept = compute_accept_from_unicode(request.headers_in['Sec-WebSocket-Key'])
15*6777b538SAndroid Build Coastguard Worker  message = (b'HTTP/1.1 101 Switching Protocols\r\n'
16*6777b538SAndroid Build Coastguard Worker             b'Upgrade: websocket\r\n'
17*6777b538SAndroid Build Coastguard Worker             b'Connection: Upgrade\r\n'
18*6777b538SAndroid Build Coastguard Worker             b'Sec-WebSocket-Accept: %s\r\n'
19*6777b538SAndroid Build Coastguard Worker             b'Sec-WebSocket-Protocol: sip \r\n'
20*6777b538SAndroid Build Coastguard Worker             b'\r\n' % accept)
21*6777b538SAndroid Build Coastguard Worker  request.connection.write(message)
22*6777b538SAndroid Build Coastguard Worker  # Prevent pywebsocket from sending its own handshake message.
23*6777b538SAndroid Build Coastguard Worker  raise handshake.AbortedByUserException('Close the connection')
24*6777b538SAndroid Build Coastguard Worker
25*6777b538SAndroid Build Coastguard Worker
26*6777b538SAndroid Build Coastguard Workerdef web_socket_transfer_data(request):
27*6777b538SAndroid Build Coastguard Worker  pass
28