engine.io
Advanced tools
Comparing version 0.9.0 to 1.0.0
1.0.0 / 2014-03-06 | ||
================== | ||
* polling-xhr: added `OPTIONS` support, fixes CORS | ||
* close() properly when triggered in connection handler | ||
* fix DDOS vector by setting up too many intervals | ||
* binary support | ||
0.9.0 / 2014-02-09 | ||
@@ -3,0 +11,0 @@ ================== |
@@ -213,2 +213,7 @@ | ||
var transport = new transports[transport](req); | ||
if (req.query && req.query.b64) { | ||
transport.supportsBinary = false; | ||
} else { | ||
transport.supportsBinary = true; | ||
} | ||
} | ||
@@ -232,3 +237,2 @@ catch (e) { | ||
this.clientsCount++; | ||
this.emit('connection', socket); | ||
@@ -239,2 +243,4 @@ socket.once('close', function(){ | ||
}); | ||
this.emit('connection', socket); | ||
}; | ||
@@ -293,2 +299,7 @@ | ||
var transport = new transports[req.query.transport](req); | ||
if (req.query && req.query.b64) { | ||
transport.supportsBinary = false; | ||
} else { | ||
transport.supportsBinary = true; | ||
} | ||
this.clients[id].maybeUpgrade(transport); | ||
@@ -295,0 +306,0 @@ } |
@@ -29,2 +29,6 @@ /** | ||
this.request = req; | ||
this.checkIntervalTimer = null; | ||
this.upgradeTimeoutTimer = null; | ||
this.pingTimeoutTimer = null; | ||
@@ -162,2 +166,3 @@ this.setTransport(transport); | ||
clearInterval(self.checkIntervalTimer); | ||
self.checkIntervalTimer = null; | ||
if ('open' == transport.readyState) { | ||
@@ -171,2 +176,3 @@ transport.close(); | ||
transport.send([{ type: 'pong', data: 'probe' }]); | ||
clearInterval(self.checkIntervalTimer); | ||
self.checkIntervalTimer = setInterval(check, 100); | ||
@@ -182,2 +188,3 @@ } else if ('upgrade' == packet.type && self.readyState == 'open') { | ||
clearInterval(self.checkIntervalTimer); | ||
self.checkIntervalTimer = null; | ||
clearTimeout(self.upgradeTimeoutTimer); | ||
@@ -226,2 +233,3 @@ transport.removeListener('packet', onPacket); | ||
clearInterval(this.checkIntervalTimer); | ||
this.checkIntervalTimer = null; | ||
clearTimeout(this.upgradeTimeoutTimer); | ||
@@ -228,0 +236,0 @@ var self = this; |
@@ -8,2 +8,3 @@ | ||
var Transport = require('../transport'); | ||
var debug = require('debug')('engine:polling-xhr'); | ||
@@ -33,2 +34,21 @@ /** | ||
/** | ||
* Overrides `onRequest` to handle `OPTIONS`.. | ||
* | ||
* @param {http.ServerRequest} | ||
* @api private | ||
*/ | ||
XHR.prototype.onRequest = function (req) { | ||
if ('OPTIONS' == req.method) { | ||
var res = req.res; | ||
var headers = this.headers(req); | ||
headers['Access-Control-Allow-Headers'] = 'Content-Type'; | ||
res.writeHead(200, headers); | ||
res.end(); | ||
} else { | ||
Polling.prototype.onRequest.call(this, req); | ||
} | ||
}; | ||
/** | ||
* Frames data prior to write. | ||
@@ -41,5 +61,11 @@ * | ||
// explicit UTF-8 is required for pages not served under utf | ||
var isString = typeof data == 'string'; | ||
var contentType = isString | ||
? 'text/plain; charset=UTF-8' | ||
: 'application/octet-stream'; | ||
var contentLength = '' + (isString ? Buffer.byteLength(data) : data.length); | ||
var headers = { | ||
'Content-Type': 'text/plain; charset=UTF-8', | ||
'Content-Length': Buffer.byteLength(data) | ||
'Content-Type': contentType, | ||
'Content-Length': contentLength | ||
}; | ||
@@ -46,0 +72,0 @@ |
@@ -24,3 +24,3 @@ | ||
Transport.call(this, req); | ||
}; | ||
} | ||
@@ -118,10 +118,12 @@ /** | ||
} else { | ||
var isBinary = 'application/octet-stream' == req.headers['content-type']; | ||
this.dataReq = req; | ||
this.dataRes = res; | ||
var chunks = '' | ||
var chunks = isBinary ? new Buffer(0) : '' | ||
, self = this | ||
function cleanup () { | ||
chunks = ''; | ||
chunks = isBinary ? new Buffer(0) : ''; | ||
req.removeListener('data', onData); | ||
@@ -139,3 +141,7 @@ req.removeListener('end', onEnd); | ||
function onData (data) { | ||
chunks += data; | ||
if (typeof data == 'string') { | ||
chunks += data; | ||
} else { | ||
chunks = Buffer.concat([chunks, data]); | ||
} | ||
}; | ||
@@ -159,3 +165,3 @@ | ||
req.on('end', onEnd); | ||
req.setEncoding('utf8'); | ||
if (!isBinary) { req.setEncoding('utf8'); } | ||
} | ||
@@ -174,3 +180,3 @@ }; | ||
var self = this; | ||
parser.decodePayload(data, function(packet){ | ||
var callback = function(packet) { | ||
if ('close' == packet.type) { | ||
@@ -183,3 +189,5 @@ debug('got xhr close packet'); | ||
self.onPacket(packet); | ||
}); | ||
}; | ||
parser.decodePayload(data, callback); | ||
}; | ||
@@ -202,3 +210,6 @@ | ||
this.write(parser.encodePayload(packets)); | ||
var self = this; | ||
parser.encodePayload(packets, this.supportsBinary, function(data) { | ||
self.write(data); | ||
}); | ||
}; | ||
@@ -205,0 +216,0 @@ |
@@ -86,11 +86,12 @@ | ||
WebSocket.prototype.send = function (packets) { | ||
var self = this; | ||
for (var i = 0, l = packets.length; i < l; i++) { | ||
var data = parser.encodePacket(packets[i]); | ||
debug('writing "%s"', data); | ||
this.writable = false; | ||
var self = this; | ||
this.socket.send(data, function (err){ | ||
if (err) return self.onError('write error', err.stack); | ||
self.writable = true; | ||
self.emit('drain'); | ||
parser.encodePacket(packets[i], this.supportsBinary, function(data) { | ||
debug('writing "%s"', data); | ||
self.writable = false; | ||
self.socket.send(data, function (err){ | ||
if (err) return self.onError('write error', err.stack); | ||
self.writable = true; | ||
self.emit('drain'); | ||
}); | ||
}); | ||
@@ -97,0 +98,0 @@ } |
{ | ||
"name": "engine.io", | ||
"version": "0.9.0", | ||
"version": "1.0.0", | ||
"description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server", | ||
@@ -21,3 +21,3 @@ "main": "./lib/engine.io", | ||
"ws": "0.4.31", | ||
"engine.io-parser": "0.3.0", | ||
"engine.io-parser": "1.0.0", | ||
"base64id": "0.1.0" | ||
@@ -29,3 +29,3 @@ }, | ||
"superagent": "0.15.4", | ||
"engine.io-client": "0.9.0", | ||
"engine.io-client": "1.0.0", | ||
"s": "0.1.1" | ||
@@ -32,0 +32,0 @@ }, |
@@ -23,2 +23,3 @@ | ||
socket.send('utf 8 string'); | ||
socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data | ||
}); | ||
@@ -72,2 +73,19 @@ ``` | ||
Sending and receiving binary | ||
```html | ||
<script src="/path/to/engine.io.js"></script> | ||
<script> | ||
var socket = new eio.Socket('ws://localhost/'); | ||
socket.binaryType = 'blob'; // receives Blob instead of ArrayBuffer (default) | ||
socket.on('open', function () { | ||
socket.send(new Int8Array(5)); | ||
socket.on('message', function (data) { | ||
// data instanceof Blob => true when receiving binary | ||
}); | ||
socket.on('close', function () { }); | ||
}); | ||
</script> | ||
``` | ||
For more information on the client refer to the | ||
@@ -226,3 +244,3 @@ [engine-client](http://github.com/learnboost/engine.io-client) repository. | ||
- **Arguments** | ||
- `String`: Unicode string | ||
- `String` or `Buffer`: Unicode string or Buffer with binary contents | ||
- `error` | ||
@@ -261,5 +279,6 @@ - Fired when an error occurs. | ||
- `send`: | ||
- Sends a message, performing `message = toString(arguments[0])`. | ||
- Sends a message, performing `message = toString(arguments[0])` unless | ||
sending binary data, which is sent as is. | ||
- **Parameters** | ||
- `String`: a string or any object implementing `toString()`, with outgoing data | ||
- `String` | `Buffer` | `ArrayBuffer` | `ArrayBufferView`: a string or any object implementing `toString()`, with outgoing data, or a Buffer or ArrayBuffer with binary data. Also any ArrayBufferView can be sent as is. | ||
- `Function`: optional, a callback executed when the message gets flushed out by the transport | ||
@@ -328,34 +347,7 @@ - **Returns** `Socket` for chaining | ||
### Unit/Integration | ||
Tests run with `make test`. It runs the server tests that are aided by | ||
the usage of `engine.io-client`. | ||
``` | ||
$ make test | ||
``` | ||
Make sure `npm install` is run first. | ||
### Acceptance | ||
``` | ||
# make test-acceptance | ||
``` | ||
And point browser/s to `http://localhost:3000`. | ||
### Server | ||
## Benchmarks | ||
### Server | ||
``` | ||
$ make bench | ||
``` | ||
### Client | ||
``` | ||
$ make bench-server | ||
``` | ||
And point browser/s to `http://localhost:3000`. | ||
## Goals | ||
@@ -362,0 +354,0 @@ |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
62236
1406
0
499
+ Addedafter@0.8.1(transitive)
+ Addedarraybuffer.slice@0.0.5(transitive)
+ Addedbase64-arraybuffer@0.1.0(transitive)
+ Addedengine.io-parser@1.0.0(transitive)
- Removedengine.io-parser@0.3.0(transitive)
Updatedengine.io-parser@1.0.0