trailing-whitespace_wsh.py 1.0 KB

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