diff --git a/lib/websocket-server.js b/lib/websocket-server.js index 70513edf2..707bd0849 100644 --- a/lib/websocket-server.js +++ b/lib/websocket-server.js @@ -251,7 +251,7 @@ class WebSocketServer extends EventEmitter { var protocol = req.headers['sec-websocket-protocol']; if (protocol) { - protocol = protocol.trim().split(/ *, */); + protocol = protocol.split(',').map(trim); // // Optionally call external protocol selection handler. @@ -355,3 +355,15 @@ function abortHandshake (socket, code, message, headers) { socket.removeListener('error', socketOnError); socket.destroy(); } + +/** + * Remove whitespace characters from both ends of a string. + * + * @param {String} str The string + * @return {String} A new string representing `str` stripped of whitespace + * characters from both its beginning and end + * @private + */ +function trim(str) { + return str.trim(); +}