WebSocket: Implement hybi handshake
authoryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jul 2011 05:32:44 +0000 (05:32 +0000)
committeryutak@chromium.org <yutak@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 14 Jul 2011 05:32:44 +0000 (05:32 +0000)
commit6fa966e7d5be61b220f7b4ca0e28c629b589f68a
tree9130a5aa3cb5f8e1019d5f322a2b2c96e44fc369
parent06e5c81674ca8b30b9db1bf6ecc5cd7c18f6246c
WebSocket: Implement hybi handshake
https://bugs.webkit.org/show_bug.cgi?id=64344

Reviewed by Kent Tamura.

Source/WebCore:

Implement WebSocket handshake which is described at
<http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10#section-5.1>.

Notable differences from hixie-76 protocol are:
- Challenge-response scheme has been changed dramatically.
- Servers do not send Sec-WebSocket-Location and Sec-WebSocket-Origin anymore.
- The value of "Upgrade" header has been changed to "websocket" (lower-case only).
- "Origin" header in client's request is renamed to "Sec-WebSocket-Origin".

New tests: http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header.html
           http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header.html
           http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header.html

Note: Tests under hybi/ directory (including the new ones) are skipped and cannot be enabled
yet, because pywebsocket does not accept requests from half-baked client implementation
(i.e. hybi handshake + hixie-76 framing). They will be unskipped when hybi framing is landed
in WebCore.

* websockets/WebSocketHandshake.cpp:
Functions and members only used for hixie-76 handshake are renamed so that they are not confused
with hybi-10's ones.
(WebCore::generateHixie76SecWebSocketKey):
(WebCore::generateHixie76Key3):
(WebCore::generateHixie76ExpectedChallengeResponse):
(WebCore::generateSecWebSocketKey):
Generates a value for Sec-WebSocket-Key as stated in hybi-10.
(WebCore::getExpectedWebSocketAccept):
Calculates the expected value of Sec-WebSocket-Accept.
(WebCore::WebSocketHandshake::WebSocketHandshake):
(WebCore::WebSocketHandshake::clientHandshakeMessage):
(WebCore::WebSocketHandshake::clientHandshakeRequest):
(WebCore::WebSocketHandshake::readServerHandshake):
(WebCore::WebSocketHandshake::serverWebSocketAccept):
(WebCore::WebSocketHandshake::serverWebSocketExtensions):
(WebCore::WebSocketHandshake::checkResponseHeaders):
* websockets/WebSocketHandshake.h:

LayoutTests:

Fix existing tests so they match the new handshake format, and add tests for new header fields.

There are several changes in the format of handshake response, such as:
- Reason string in HTTP status line has been changed to "Switching Protocols".
- The value of "Upgrade" header has been changed to "websocket" (lower-case only).
- Sec-WebSocket-Location and Sec-WebSocket-Origin are gone.
- "Challenge response" value (16-byte data after the response header fields) is removed, and
  Sec-WebSocket-Accept header is added instead.

The value of Sec-WebSocket-Accept header is computed using compute_accept() function
located in mod_pywebsocket.handshake.hybi06 module. Although the module name contains
"hybi06", this function can be used to calculate the value of Sec-WebSocket-Accept header
for hybi-10 (calculation method has not been changed since hybi-06).

Note: Tests under hybi/ directory (including the new ones) are skipped and cannot be enabled
yet, because pywebsocket does not accept requests from half-baked client implementation
(i.e. hybi handshake + hixie-76 framing). They will be unskipped when hybi framing is landed
in WebCore.

* http/tests/websocket/tests/handler_map.txt:
There must be only one handler that can handle requests to "/". hybi/echo-location_wsh.py
is modified to accept requests of both protocol versions.
* http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py:
* http/tests/websocket/tests/hybi/echo-challenge_wsh.py:
* http/tests/websocket/tests/hybi/echo-location_wsh.py:
* http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py:
* http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header_wsh.py: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py:
* http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py:
* http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py:
* http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py:
* http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header-expected.txt: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header.html: Added.
* http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header_wsh.py: Added.
* http/tests/websocket/tests/hybi/long-invalid-header_wsh.py:
* http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@90979 268f45cc-cd09-0410-ab3c-d52691b4dbfc
24 files changed:
LayoutTests/ChangeLog
LayoutTests/http/tests/websocket/tests/handler_map.txt
LayoutTests/http/tests/websocket/tests/hybi/bad-handshake-crash_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/echo-challenge_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/echo-location_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-extensions-header_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-maxlength_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-accept-header_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-connection-header_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-cr_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-no-upgrade-header_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-prepended-null_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header-expected.txt [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header.html [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/handshake-fail-by-wrong-accept-header_wsh.py [new file with mode: 0644]
LayoutTests/http/tests/websocket/tests/hybi/long-invalid-header_wsh.py
LayoutTests/http/tests/websocket/tests/hybi/workers/resources/echo-challenge_wsh.py
Source/WebCore/ChangeLog
Source/WebCore/websockets/WebSocketHandshake.cpp
Source/WebCore/websockets/WebSocketHandshake.h