klacke/yaws — Issue #73: WebSockets Protocol Header is not respected
Author: limitlessperspective
Created: 2011-12-23 09:03:14+00:00
State: open

yaws_websockets.erl:94
The protocol/subprotocol are retrieved but are never passed to handle_message. In theory, the opcode/protocol attribute of #ws_frame_info or #ws_state should be a list of the values of sec-websockets-protocol header converted into atoms.

Every message that is sent between the client and server has a text opcode and does not respect the protocol that the client selects.

Below are the additions that are needed in yaws_websockets.erl. I thought that it would be wasteful and time consuming for me to create another branch.

108 ++ ProtocolList = string:tokens(Protocol, " "),
109 ++ ProtocolOpcode = list_to_atom(ProtocolList),
110 -- WSState = #ws_state{sock = CliSock, vsn = ProtocolVersion, frag_type=none},
110: WSState = #ws_state{sock = CliSock, vsn = ProtocolVersion, frag_type=ProtocolOpcode},

It is an extremely dirty fix, but it does not break anything. handle_message now needs to be in the format:

handle_message(#ws_frame_info, #ws_state{frag_type=[binary, base64]) ->

Where [binary, base64] is your protocol and subprotocol(s)–the list can be n-elements long.