Throw an error if drivers are created with unrecognised options.

This commit is contained in:
James Coglan
2014-12-17 22:12:56 +00:00
parent e8992add23
commit 5cba268409
2 changed files with 14 additions and 1 deletions
+6 -1
View File
@@ -6,7 +6,8 @@
// * http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76
// * http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17
var Client = require('./driver/client'),
var Base = require('./driver/base'),
Client = require('./driver/client'),
Server = require('./driver/server');
var Driver = {
@@ -39,6 +40,10 @@ var Driver = {
return request.method === 'GET' &&
connection.toLowerCase().split(/ *, */).indexOf('upgrade') >= 0 &&
upgrade.toLowerCase() === 'websocket';
},
validateOptions: function(options, validKeys) {
Base.validateOptions(options, validKeys);
}
};
+8
View File
@@ -7,6 +7,7 @@ var Emitter = require('events').EventEmitter,
var Base = function(request, url, options) {
Emitter.call(this);
Base.validateOptions(options || {}, ['maxLength', 'masking', 'requireMasking', 'protocols']);
this._request = request;
this._options = options || {};
@@ -22,6 +23,13 @@ var Base = function(request, url, options) {
};
util.inherits(Base, Emitter);
Base.validateOptions = function(options, validKeys) {
for (var key in options) {
if (validKeys.indexOf(key) < 0)
throw new Error('Unrecognized option: ' + key);
}
};
var instance = {
// This is 64MB, small enough for an average VPS to handle without
// crashing from process out of memory