cesanta / mongoose

Embedded Web Server
https://mongoose.ws
Other
11.17k stars 2.73k forks source link

Websocket (Sec-WebSocket-Protocol) strict support #257

Closed motmot80 closed 10 years ago

motmot80 commented 11 years ago

Hi,

if a websocket client requests a subprotocol (Sec-WebSocket-Protocol) the server should return the subprotocol to the client. RFC 6455 4.2.2 5,6 . I think it's only optional if the client does NOT request a subprotocol.

Chrome > 29 handles this strictly and denies any websocket connection with subprotocol not responded/recognized by the server:

"WebSocket connection to 'ws://server' failed: Error during WebSocket handshake: Sec-WebSocket-Protocol mismatch‏"

I fixed this by simply adding the "Sec-WebSocket-Protocol" with the client subprotocol - if there's any. (dirty stuff : )

There should be an callback or something to react on a client subprotocol request.

Thanks for your great work.

Best regards, Thomas

motmot80 commented 11 years ago

It seems like #175 covers a similar subject.

cpq commented 10 years ago

I believe with the synchronous API, server can inject pretty much anything after the handshake. Take a look at https://github.com/cesanta/mongoose/blob/master/examples/websocket.c#L25.