Comparing version 0.0.15 to 0.0.16
@@ -7,3 +7,3 @@ module.exports = { | ||
"request" : require('./WebSocketRequest'), | ||
"version" : "0.0.15" | ||
"version" : "0.0.16" | ||
}; |
@@ -80,3 +80,2 @@ /************************************************************************ | ||
this.serverConfig = serverConfig; | ||
this.readHandshake(httpRequest); | ||
}; | ||
@@ -86,3 +85,4 @@ | ||
WebSocketRequest.prototype.readHandshake = function(request) { | ||
WebSocketRequest.prototype.readHandshake = function() { | ||
var request = this.httpRequest; | ||
this.host = request.headers['host']; | ||
@@ -95,3 +95,2 @@ if (!this.host) { | ||
if (!this.key) { | ||
this.reject(400, "Client must provide a value for Sec-WebSocket-Key."); | ||
throw new Error("Client must provide a value for Sec-WebSocket-Key."); | ||
@@ -104,10 +103,11 @@ } | ||
if (!this.websocketVersion) { | ||
this.reject(400, "Client must provide a value for Sec-WebSocket-Version."); | ||
throw new Error("Client must provide a value for Sec-WebSocket-Version."); | ||
} | ||
if (this.websocketVersion !== '8') { | ||
this.reject(426, "Unsupported websocket client version.", { | ||
var e = new Error("Unsupported websocket client version: " + this.websocketVersion); | ||
e.httpCode = 426; | ||
e.headers = { | ||
"Sec-WebSocket-Version": "8" | ||
}); | ||
throw new Error("Unsupported websocket client version. Client requested version " + this.websocketVersion + ", but we only support version 8."); | ||
}; | ||
throw e; | ||
} | ||
@@ -114,0 +114,0 @@ |
@@ -138,7 +138,13 @@ /************************************************************************ | ||
WebSocketServer.prototype.handleUpgrade = function(request, socket, head) { | ||
var wsRequest = new WebSocketRequest(socket, request, this.config); | ||
try { | ||
var wsRequest = new WebSocketRequest(socket, request, this.config); | ||
wsRequest.readHandshake(); | ||
} | ||
catch(e) { | ||
console.error((new Date()) + " WebSocket: Invalid handshake: " + e.toString()); | ||
wsRequest.reject( | ||
e.httpCode ? e.httpCode : 400, | ||
e.message, | ||
e.headers | ||
); | ||
console.error((new Date()) + " WebSocket: Invalid handshake: " + e.message); | ||
return; | ||
@@ -145,0 +151,0 @@ } |
@@ -6,3 +6,3 @@ { | ||
"author": "Brian McKelvey <brian@worlize.com>", | ||
"version": "0.0.15", | ||
"version": "0.0.16", | ||
"repository": { | ||
@@ -9,0 +9,0 @@ "type": "git", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7264
290838