Bug 85737 - WebSocket-Protocol header not implemented correctly
Summary: WebSocket-Protocol header not implemented correctly
Status: RESOLVED WONTFIX
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-06 09:58 PDT by Markus Fenske
Modified: 2012-05-07 22:05 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Fenske 2012-05-06 09:58:13 PDT
Hi,

I am reporting a bug in qt-everywhere-opensource-src-4.7.4.tar.gz. I am not quite sure, if this belongs in this bug tracker. 

I am using capybara-webkit (ruby stuff) to test against jetty websocket server. I am using the following javascript:

    socket = new WebSocket("ws://localhost:8888/api/v1/driver", "myprotocol");

The console returns: "Error during WebSocket handshake: protocol mismatch: myprotocol != "

If I look in the packet dumps, I see, that Qt Websocket is sending:

GET /api/v1/driver HTTP/1.1
Upgrade: WebSocket
Connection: Upgrade
Host: 127.0.0.1:8888
Origin: http://127.0.0.1:59227
WebSocket-Protocol: myprotocol


And the Server is responding:

HTTP/1.1 101 Web Socket Protocol Handshake
Upgrade: WebSocket
Connection: Upgrade
WebSocket-Origin: http://127.0.0.1:59227
WebSocket-Location: ws://127.0.0.1:8888/api/v1/driver

There is no WebSocket-Protocol Header from the server, because according to the RFCs I found, it is only needed if the server does use a protocol not specified by the client. In this case, the Server uses the "myprotocol" protocol, so no WebSocket-Protocol header is needed. I tracked down the issue to qt-everywhere-opensource-src-4.7.4/src/3rdparty/webkit/WebCore/websockets/WebSocketHandshake.cpp. The following patch fixes it.


--- WebSocketHandshake.cpp.old	2012-05-06 18:35:33.659494866 +0200
+++ WebSocketHandshake.cpp	2012-05-06 18:35:36.179513204 +0200
@@ -491,7 +491,7 @@
         m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: location mismatch: " + clientLocation() + " != " + m_wsLocation, 0, clientOrigin());
         return;
     }
-    if (!m_clientProtocol.isEmpty() && m_clientProtocol != m_wsProtocol) {
+    if (!m_wsProtocol.isEmpty() && m_clientProtocol != m_wsProtocol) {
         m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: protocol mismatch: " + m_clientProtocol + " != " + m_wsProtocol, 0, clientOrigin());
         return;
     }
Comment 1 Li Yin 2012-05-07 19:47:16 PDT
(In reply to comment #0)
> Hi,
> 
> I am reporting a bug in qt-everywhere-opensource-src-4.7.4.tar.gz. I am not quite sure, if this belongs in this bug tracker. 
> 
> I am using capybara-webkit (ruby stuff) to test against jetty websocket server. I am using the following javascript:
> 
>     socket = new WebSocket("ws://localhost:8888/api/v1/driver", "myprotocol");
> 
> The console returns: "Error during WebSocket handshake: protocol mismatch: myprotocol != "
> 
> If I look in the packet dumps, I see, that Qt Websocket is sending:
> 
> GET /api/v1/driver HTTP/1.1
> Upgrade: WebSocket
> Connection: Upgrade
> Host: 127.0.0.1:8888
> Origin: http://127.0.0.1:59227
> WebSocket-Protocol: myprotocol
> 
> 
> And the Server is responding:
> 
> HTTP/1.1 101 Web Socket Protocol Handshake
> Upgrade: WebSocket
> Connection: Upgrade
> WebSocket-Origin: http://127.0.0.1:59227
> WebSocket-Location: ws://127.0.0.1:8888/api/v1/driver
> 
> There is no WebSocket-Protocol Header from the server, because according to the RFCs I found, it is only needed if the server does use a protocol not specified by the client. In this case, the Server uses the "myprotocol" protocol, so no WebSocket-Protocol header is needed. I tracked down the issue to qt-everywhere-opensource-src-4.7.4/src/3rdparty/webkit/WebCore/websockets/WebSocketHandshake.cpp. The following patch fixes it.
> 
> 
> --- WebSocketHandshake.cpp.old    2012-05-06 18:35:33.659494866 +0200
> +++ WebSocketHandshake.cpp    2012-05-06 18:35:36.179513204 +0200
> @@ -491,7 +491,7 @@
>          m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: location mismatch: " + clientLocation() + " != " + m_wsLocation, 0, clientOrigin());
>          return;
>      }
> -    if (!m_clientProtocol.isEmpty() && m_clientProtocol != m_wsProtocol) {
> +    if (!m_wsProtocol.isEmpty() && m_clientProtocol != m_wsProtocol) {
>          m_context->addMessage(ConsoleDestination, JSMessageSource, LogMessageType, ErrorMessageLevel, "Error during WebSocket handshake: protocol mismatch: " + m_clientProtocol + " != " + m_wsProtocol, 0, clientOrigin());
>          return;
>      }

You are working on Hixie76Protocol, maybe it will be abandoned by webkit in the near future.
We are working on the new WebSocket protocol RFC6455 http://tools.ietf.org/html/rfc6455
Comment 2 Yuta Kitamura 2012-05-07 22:05:49 PDT
Right, the old protocol isn't used anymore (Qt has switched the protocol recently), and we are going to vanish code and tests for the old protocol soon.

So, I'm resolving this issue as WONTFIX. If there's an issue with the RFC protocol version, please speak up or open a new bug.

Furthermore, if you are going to contribute a patch in the future, please follow the instruction at http://www.webkit.org/coding/contributing.html and upload your patch to the bugzilla (instead of pasting the diff in comments) so we can review it smoothly.