einaros/ws — pull request #198 by kanaka (2013-05-29 02:34:03+00:00)
Title: Add subprotocol support

- The client will set ws.protocol based on the subprotocol returned by
the server. Fixes #192.
- The server application can select from multiple client subprotocol
options by specifying a handleProtocols in initialization options.
This function takes two arguments; the first is an array of
subprotocols sent by the client (empty array if no subprotocol
specified by the client), the second is a callback function. The
callback function takes two arguments; the first indicates if the
client subprotocols are valid, the second argument (only passed when
first is true) is the subprotocol string selected to return to the
client. Fixes #29. Fixes #193.
- The default subprotocol behavior of the server is to select/return
the first subprotocol in the list.
- Includes 6 tests to test subprotocol support:
- test default behavior of selecting first subprotocol
- test custom handleProtocols that selects a subprotocol
- detect server sending invalid subprotocol
- detect server sent no subprotocol even though client sent
subprotocol header.
- test custom handleProtocols that rejects connection based on
invalid client subprotocol request.
- server responds with 501 to client if the handleProtocols
handler neither selects a protocol nor rejects the connection.