xref: /aosp_15_r20/external/cronet/net/data/websocket/protocol-test_wsh.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1*6777b538SAndroid Build Coastguard Worker# Copyright 2012 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 Workerfrom mod_pywebsocket import msgutil
6*6777b538SAndroid Build Coastguard Workerfrom six.moves.urllib import parse
7*6777b538SAndroid Build Coastguard Worker
8*6777b538SAndroid Build Coastguard Worker
9*6777b538SAndroid Build Coastguard Workerdef web_socket_do_extra_handshake(request):
10*6777b538SAndroid Build Coastguard Worker  r = request.ws_resource.split('?', 1)
11*6777b538SAndroid Build Coastguard Worker  if len(r) == 1:
12*6777b538SAndroid Build Coastguard Worker    return
13*6777b538SAndroid Build Coastguard Worker  param = parse.parse_qs(r[1])
14*6777b538SAndroid Build Coastguard Worker  if 'protocol' in param:
15*6777b538SAndroid Build Coastguard Worker    request.ws_protocol = param['protocol'][0]
16*6777b538SAndroid Build Coastguard Worker
17*6777b538SAndroid Build Coastguard Worker
18*6777b538SAndroid Build Coastguard Workerdef web_socket_transfer_data(request):
19*6777b538SAndroid Build Coastguard Worker  msgutil.send_message(request, request.ws_protocol)
20*6777b538SAndroid Build Coastguard Worker  # Wait for a close message.
21*6777b538SAndroid Build Coastguard Worker  unused = request.ws_stream.receive_message()
22