Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / LayoutTests / http / tests / websocket / handshake-fail-by-maxlength_wsh.py
1 # Copyright (C) Research In Motion Limited 2011. All rights reserved.
2 #
3 # Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
4 # following conditions are met:
5 #
6 # 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
7 # disclaimer.
8 #
9 # 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
10 # following disclaimer in the documentation and/or other materials provided with the distribution.
11 #
12 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS “AS IS” AND ANY EXPRESS OR
13 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
14 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
15 # APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
16 # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
17 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
18 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
19 # TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
20 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
22
23 from mod_pywebsocket import handshake
24 from mod_pywebsocket.handshake.hybi import compute_accept
25
26
27 def web_socket_do_extra_handshake(request):
28     # This will cause the handshake to fail because it pushes the length of the
29     # status line past 1024 characters
30     msg = '.' * 1024
31     msg += 'HTTP/1.1 101 Switching Protocols\r\n'
32     msg += 'Upgrade: websocket\r\n'
33     msg += 'Connection: Upgrade\r\n'
34     msg += 'Sec-WebSocket-Accept: %s\r\n' % compute_accept(request.headers_in['Sec-WebSocket-Key'])[0]
35     msg += '\r\n'
36     request.connection.write(msg)
37     # Prevents pywebsocket from sending its own handshake message.
38     raise handshake.AbortedByUserException('abort the connection')
39
40
41 def web_socket_transfer_data(request):
42     pass