Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
options.httpServer.on('upgrade', function(req, socket, head) {
if (typeof req.headers['sec-websocket-version'] !== 'undefined') {
// WebSocket hybi-08/-09/-10 connection (WebSocket-Node)
wsRequest = new WebSocketRequest(socket, req, wsServerConfig);
try {
wsRequest.readHandshake();
} catch (e) {
wsRequest.reject(
e.httpCode ? e.httpCode : 400,
e.message,
e.headers
);
return;
}
wsRequest.once('requestAccepted', function(connection) {
wsRequest.handleRequestAccepted(connection);
});
self.emit('request', wsRequest);
} else {
httpServer.on('upgrade', function(req, socket, head) {
if (typeof req.headers['sec-websocket-version'] !== 'undefined') {
// WebSocket hybi-08/-09/-10 connection (WebSocket-Node)
var wsRequest = new WebSocketRequest(socket, req, wsServerConfig);
try {
wsRequest.readHandshake();
var wsConnection = wsRequest.accept(wsRequest.requestedProtocols[0], wsRequest.origin);
handleConnection(wsConnection);
}
catch(e) {
console.log("WebSocket Request unsupported by WebSocket-Node: " + e.toString());
return;
}
} else {
// WebSocket hixie-75/-76/hybi-00 connection (node-websocket-server)
if (req.method === 'GET' &&
(req.headers.upgrade && req.headers.connection) &&
req.headers.upgrade.toLowerCase() === 'websocket' &&
primary.on("upgrade", function(request, socket, head) {
if ("sec-websocket-version" in request.headers) {
request = new websocket.request(socket, request, wsOptions);
request.readHandshake();
connect(request.accept(request.requestedProtocols[0], request.origin), request.httpRequest);
} else if (request.method === "GET"
&& /^websocket$/i.test(request.headers.upgrade)
&& /^upgrade$/i.test(request.headers.connection)) {
new websprocket.Connection(secondary.manager, secondary.options, request, socket, head);
}
});
function auth_ok(perms) {
if (is_sec_ws_initiation(request)) {
request = new websocket.request(socket, request, wsOptions);
request.readHandshake();
connect(request.accept(request.requestedProtocols[0], request.origin), request.httpRequest);
} else if (is_ws_initiation(request)) {
new websprocket.Connection(secondary.manager, secondary.options, request, socket, head);
}
}
function auth_no(perms) {
function auth_no(perms) {
if (is_sec_ws_initiation(request)) {
request = new websocket.request(socket, request, wsOptions);
request.readHandshake();
request.reject();
} else if (is_ws_initiation(request)) {
res = 'HTTP/1.1 403 Forbidden\r\nConnection: close';
socket.end(res + '\r\n\r\n', 'ascii');
}
}
return authenticator.check(request, auth_ok, auth_no);