Compare commits

...

4 Commits

Author SHA1 Message Date
James Coglan dbedb370b7 Bump version to 0.3.5. 2014-07-06 10:18:19 +01:00
James Coglan 28858d9fb3 Delegate the protocol and version methods correctly in the TCP driver. 2014-07-04 17:49:11 +01:00
James Coglan ae52cf995e Stop the Hybi parser hanging onto data it doesn't need after emitFrame(). 2014-06-16 20:30:44 +01:00
James Coglan dfe7b2b000 Trailing blank lines are bad. 2014-05-17 00:35:31 +01:00
21 changed files with 43 additions and 60 deletions
-1
View File
@@ -8,4 +8,3 @@ node_js:
before_install:
- '[ "${TRAVIS_NODE_VERSION}" = "0.6" ] && npm conf set strict-ssl false || true'
+5 -1
View File
@@ -1,3 +1,8 @@
### 0.3.5 / 2014-07-06
* Don't hold references to frame buffers after a message has been emitted
* Make sure that `protocol` and `version` are exposed properly by the TCP driver
### 0.3.4 / 2014-05-08
* Don't hold memory-leaking references to I/O buffers after they have been parsed
@@ -39,4 +44,3 @@
### 0.1.0 / 2013-05-04
* First stable release
-1
View File
@@ -304,4 +304,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
-1
View File
@@ -18,4 +18,3 @@ var server = net.createServer(function(connection) {
});
server.listen(process.argv[2]);
-1
View File
@@ -41,4 +41,3 @@ var Driver = {
};
module.exports = Driver;
-1
View File
@@ -123,4 +123,3 @@ Base.MessageEvent = function(data) {
};
module.exports = Base;
-1
View File
@@ -109,4 +109,3 @@ for (var key in instance)
Client.prototype[key] = instance[key];
module.exports = Client;
-1
View File
@@ -115,4 +115,3 @@ for (var key in instance)
Draft75.prototype[key] = instance[key];
module.exports = Draft75;
-1
View File
@@ -106,4 +106,3 @@ for (var key in instance)
Draft76.prototype[key] = instance[key];
module.exports = Draft76;
-1
View File
@@ -27,4 +27,3 @@ Headers.prototype._strip = function(string) {
};
module.exports = Headers;
-1
View File
@@ -78,4 +78,3 @@ HttpParser.prototype.parse = function(data) {
};
module.exports = HttpParser;
+34 -39
View File
@@ -7,26 +7,33 @@ var Hybi = function(request, url, options) {
Base.apply(this, arguments);
this._reset();
this._reader = new Reader();
this._stage = 0;
this._masking = this._options.masking;
this._protocols = this._options.protocols || [];
this._reader = new Reader();
this._stage = 0;
this._masking = this._options.masking;
this._protocols = this._options.protocols || [];
this._requireMasking = this._options.requireMasking;
this._pingCallbacks = {};
if (typeof this._protocols === 'string')
this._protocols = this._protocols.split(/\s*,\s*/);
this._requireMasking = this._options.requireMasking;
this._pingCallbacks = {};
if (!this._request) return;
if (!this.version) {
var version = this._request.headers['sec-websocket-version'];
this.version = 'hybi-' + version;
var protos = this._request.headers['sec-websocket-protocol'],
supported = this._protocols;
if (protos !== undefined) {
if (typeof protos === 'string') protos = protos.split(/\s*,\s*/);
this.protocol = protos.filter(function(p) { return supported.indexOf(p) >= 0 })[0];
}
var version = this._request.headers['sec-websocket-version'];
this.version = 'hybi-' + version;
};
util.inherits(Hybi, Base);
Hybi.mask = function(payload, mask, offset) {
if (mask.length === 0) return payload;
if (!mask || mask.length === 0) return payload;
offset = offset || 0;
for (var i = 0, n = payload.length - offset; i < n; i++) {
@@ -118,8 +125,7 @@ var instance = {
case 4:
buffer = this._reader.read(this._length);
if (buffer) {
this._payload = buffer;
this._emitFrame();
this._emitFrame(buffer);
this._stage = 0;
}
break;
@@ -220,26 +226,15 @@ var instance = {
var secKey = this._request.headers['sec-websocket-key'];
if (!secKey) return '';
var accept = Hybi.generateAccept(secKey),
protos = this._request.headers['sec-websocket-protocol'],
supported = this._protocols,
proto,
var headers = [
'HTTP/1.1 101 Switching Protocols',
'Upgrade: websocket',
'Connection: Upgrade',
'Sec-WebSocket-Accept: ' + Hybi.generateAccept(secKey)
];
headers = [
'HTTP/1.1 101 Switching Protocols',
'Upgrade: websocket',
'Connection: Upgrade',
'Sec-WebSocket-Accept: ' + accept
];
if (protos !== undefined) {
if (typeof protos === 'string') protos = protos.split(/\s*,\s*/);
proto = protos.filter(function(p) { return supported.indexOf(p) >= 0 })[0];
if (proto) {
this.protocol = proto;
headers.push('Sec-WebSocket-Protocol: ' + proto);
}
}
if (this.protocol)
headers.push('Sec-WebSocket-Protocol: ' + this.protocol);
return new Buffer(headers.concat(this.__headers.toString(), '').join('\r\n'), 'utf8');
},
@@ -269,8 +264,6 @@ var instance = {
this._final = (data & this.FIN) === this.FIN;
this._opcode = (data & this.OPCODE);
this._mask = [];
this._payload = [];
if (this.OPCODE_CODES.indexOf(this._opcode) < 0)
return this._fail('protocol_error', 'Unrecognized frame opcode: ' + this._opcode);
@@ -320,14 +313,17 @@ var instance = {
}
},
_emitFrame: function() {
var payload = Hybi.mask(this._payload, this._mask),
_emitFrame: function(buffer) {
var payload = Hybi.mask(buffer, this._mask),
isFinal = this._final,
opcode = this._opcode;
this._final = this._opcode = this._length = this._lengthSize = this._masked = this._mask = null;
if (opcode === this.OPCODES.continuation) {
if (!this._mode) return this._fail('protocol_error', 'Received unexpected continuation frame');
this._buffer(payload);
if (this._final) {
if (isFinal) {
var message = this._concatBuffer();
if (this._mode === 'text') message = this._encode(message);
this._reset();
@@ -338,7 +334,7 @@ var instance = {
}
}
else if (opcode === this.OPCODES.text) {
if (this._final) {
if (isFinal) {
var message = this._encode(payload);
if (message === null)
this._fail('encoding_error', 'Could not decode a text frame as UTF-8');
@@ -350,7 +346,7 @@ var instance = {
}
}
else if (opcode === this.OPCODES.binary) {
if (this._final) {
if (isFinal) {
this.emit('message', new Base.MessageEvent(payload));
} else {
this._mode = 'binary';
@@ -426,4 +422,3 @@ for (var key in instance)
Hybi.prototype[key] = instance[key];
module.exports = Hybi;
+3 -1
View File
@@ -40,6 +40,9 @@ var instance = {
this._delegate.on(event, function(e) { self.emit(event, e) });
}, this);
this.protocol = this._delegate.protocol;
this.version = this._delegate.version;
this.parse(this._http.body);
this.emit('connect', new Base.ConnectEvent());
},
@@ -101,4 +104,3 @@ Server.http = function(request, options) {
};
module.exports = Server;
-1
View File
@@ -141,4 +141,3 @@ Messages.prototype.destroy = function() {};
exports.IO = IO;
exports.Messages = Messages;
+1 -2
View File
@@ -5,7 +5,7 @@
, "keywords" : ["websocket"]
, "license" : "MIT"
, "version" : "0.3.4"
, "version" : "0.3.5"
, "engines" : {"node": ">=0.4.0"}
, "main" : "./lib/websocket/driver"
, "devDependencies" : {"jstest": ""}
@@ -18,4 +18,3 @@
, "bugs" : "http://github.com/faye/websocket-driver-node/issues"
}
-1
View File
@@ -42,4 +42,3 @@ require('./websocket/driver/draft75_spec')
require('./websocket/driver/draft76_spec')
require('./websocket/driver/hybi_spec')
require('./websocket/driver/client_spec')
-1
View File
@@ -249,4 +249,3 @@ test.describe("Client", function() { with(this) {
}})
}})
}})
@@ -112,4 +112,3 @@ test.describe("draft-75", function() { with(this) {
}})
}})
}})
-1
View File
@@ -97,4 +97,3 @@ test.describe("Draft75", function() { with(this) {
itShouldBehaveLike("draft-75 protocol")
}})
-1
View File
@@ -184,4 +184,3 @@ test.describe("Draft76", function() { with(this) {
}})
}})
}})
-1
View File
@@ -539,4 +539,3 @@ test.describe("Hybi", function() { with(this) {
}})
}})
}})