Chrome (45) won't connect to websocket server due to "Sec-WebSocket-Protocol" missing from response
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 6.1k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
The latest version of Chrome was refusing to connect to the web socket server.
I tracked this down to and issue with the header being returned by the service.
Chrome rejects the connection if no web socket protocol value is returned back to the client in the headers. I did not see anyway without modifying the code to make this happen.
My temporary workaround to the issue was to change the HttpServer class in the "receiveRequest" method. The following code below was the issue.
if (ctx.Request.IsUpgradeTo ("websocket")) {
processRequest (ctx.AcceptWebSocket (null));
return;
}
I had to replace the "null" with a string for the protocol name that I wanted to socket to return when it sent back the headers to the connecting client. After making that change Chrome will now successfully connect to the web socket server.
PS: I also had to set the "IgnoreExtensions" property as mentioned in other posts to avoid issues with the compression.
Ideally the WebSocketBehavior class would provide a method that would allow you to "Negotiate" what protocol value to return when the connection is being established.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the HttpServer receiveRequest method described in the issue and trace how AcceptWebSocket(null) constructs the response headers. Then inspect WebSocketBehavior for the proposed negotiation entry point and verify the connection behavior with Chrome, including the IgnoreExtensions setting; done means the negotiated Sec-WebSocket-Protocol is returned without breaking existing WebSocket connections.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100