Socket
Socket
Sign inDemoInstall

engine.io

Package Overview
Dependencies
Maintainers
1
Versions
151
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

engine.io - npm Package Compare versions

Comparing version 1.0.5 to 1.1.0

10

History.md
1.1.0 / 2014-04-27
==================
* socket: removed unneeded `clearTimeout` (fixes #250)
* made the request verification process async
* package: bump `engine.io-parser`
* use _query instead of query, fixes compat with restify
* added a maximum buffer size to received data from polling
* fixing looping array via for in to normal loop
1.0.5 / 2014-03-18

@@ -3,0 +13,0 @@ ==================

88

lib/server.js

@@ -38,4 +38,6 @@

this.upgradeTimeout = opts.upgradeTimeout || 10000;
this.maxHttpBufferSize = opts.maxHttpBufferSize || 10E7;
this.transports = opts.transports || Object.keys(transports);
this.allowUpgrades = false !== opts.allowUpgrades;
this.allowRequest = opts.allowRequest;
this.cookie = false !== opts.cookie ? (opts.cookie || 'io') : false;

@@ -101,26 +103,27 @@

Server.prototype.verify = function(req, upgrade){
Server.prototype.verify = function(req, upgrade, fn){
// transport check
var transport = req.query.transport;
var transport = req._query.transport;
if (!~this.transports.indexOf(transport)) {
debug('unknown transport "%s"', transport);
return Server.errors.UNKNOWN_TRANSPORT;
return fn(Server.errors.UNKNOWN_TRANSPORT, false);
}
// sid check
var sid = req.query.sid;
var sid = req._query.sid;
if (sid) {
if (!this.clients.hasOwnProperty(sid))
return Server.errors.UNKNOWN_SID;
return fn(Server.errors.UNKNOWN_SID, false);
if (!upgrade && this.clients[sid].transport.name !== transport) {
debug('bad request: unexpected transport without upgrade');
return Server.errors.BAD_REQUEST;
return fn(Server.errors.BAD_REQUEST, false);
}
} else {
// handshake is GET only
return 'GET' == req.method ||
Server.errors.BAD_HANDSHAKE_METHOD;
if ('GET' != req.method) return fn(Server.errors.BAD_HANDSHAKE_METHOD, false);
if (!this.allowRequest) return fn(null, true);
return this.allowRequest(req, fn);
}
return true;
fn(null, true);
};

@@ -135,5 +138,5 @@

Server.prototype.prepare = function(req){
// try to leverage pre-existing `req.query` (e.g: from connect)
if (!req.query) {
req.query = ~req.url.indexOf('?') ? qs.parse(parse(req.url).query) : {};
// try to leverage pre-existing `req._query` (e.g: from connect)
if (!req._query) {
req._query = ~req.url.indexOf('?') ? qs.parse(parse(req.url).query) : {};
}

@@ -169,16 +172,16 @@ };

var code = this.verify(req, false);
if (code !== true) {
sendErrorMessage(res, code);
return this;
}
var self = this;
this.verify(req, false, function(err, success) {
if (!success) {
sendErrorMessage(res, err);
return;
}
if (req.query.sid) {
debug('setting new request for existing client');
this.clients[req.query.sid].transport.onRequest(req);
} else {
this.handshake(req.query.transport, req);
}
return this;
if (req._query.sid) {
debug('setting new request for existing client');
self.clients[req._query.sid].transport.onRequest(req);
} else {
self.handshake(req._query.transport, req);
}
});
};

@@ -215,5 +218,10 @@

var transportName = transport;
try {
var transport = new transports[transport](req);
if (req.query && req.query.b64) {
if ('polling' == transportName) {
transport.maxHttpBufferSize = this.maxHttpBufferSize;
}
if (req._query && req._query.b64) {
transport.supportsBinary = false;

@@ -259,11 +267,13 @@ } else {

if (this.verify(req, true) !== true) {
socket.end();
return;
}
var self = this;
this.verify(req, true, function(err, success) {
if (!success) {
socket.end();
return;
}
// delegate to ws
var self = this;
this.ws.handleUpgrade(req, socket, head, function(conn){
self.onWebSocket(req, conn);
// delegate to ws
self.ws.handleUpgrade(req, socket, head, function(conn){
self.onWebSocket(req, conn);
});
});

@@ -280,3 +290,3 @@ };

Server.prototype.onWebSocket = function(req, socket){
if (!transports[req.query.transport].prototype.handlesUpgrades) {
if (!transports[req._query.transport].prototype.handlesUpgrades) {
debug('transport doesnt handle upgraded requests');

@@ -288,3 +298,3 @@ socket.close();

// get client id
var id = req.query.sid;
var id = req._query.sid;

@@ -303,4 +313,4 @@ // keep a reference to the ws.Socket

debug('upgrading existing transport');
var transport = new transports[req.query.transport](req);
if (req.query && req.query.b64) {
var transport = new transports[req._query.transport](req);
if (req._query && req._query.b64) {
transport.supportsBinary = false;

@@ -313,3 +323,3 @@ } else {

} else {
this.handshake(req.query.transport, req);
this.handshake(req._query.transport, req);
}

@@ -316,0 +326,0 @@ };

@@ -215,3 +215,2 @@ /**

});
clearTimeout(this.pingIntervalTimer);
clearTimeout(this.pingTimeoutTimer);

@@ -263,3 +262,3 @@ };

debug('executing batch send callback');
for (var i in seqFn) {
for (var l = seqFn.length, i = 0; i < l; i++) {
if ('function' == typeof seqFn[i]) {

@@ -266,0 +265,0 @@ seqFn[i](self.transport);

@@ -32,3 +32,3 @@

function polling (req) {
if ('string' == typeof req.query.j) {
if ('string' == typeof req._query.j) {
return new JSONP(req);

@@ -35,0 +35,0 @@ } else {

@@ -24,3 +24,3 @@

this.head = '___eio[' + (req.query.j || '').replace(/[^0-9]/g, '') + '](';
this.head = '___eio[' + (req._query.j || '').replace(/[^0-9]/g, '') + '](';
this.foot = ');';

@@ -27,0 +27,0 @@ };

@@ -142,7 +142,15 @@

function onData (data) {
var contentLength;
if (typeof data == 'string') {
chunks += data;
contentLength = Buffer.byteLength(chunks);
} else {
chunks = Buffer.concat([chunks, data]);
contentLength = chunks.length;
}
if (contentLength > self.maxHttpBufferSize) {
chunks = '';
req.connection.destroy();
}
}

@@ -149,0 +157,0 @@

{
"name": "engine.io",
"version": "1.0.5",
"version": "1.1.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": "1.0.2",
"engine.io-parser": "1.0.4",
"base64id": "0.1.0"

@@ -29,3 +29,3 @@ },

"superagent": "0.15.4",
"engine.io-client": "1.0.5",
"engine.io-client": "1.1.0",
"s": "0.1.1"

@@ -32,0 +32,0 @@ },

@@ -21,3 +21,3 @@

server.on('connection', function (socket) {
server.on('connection', function(socket){
socket.send('utf 8 string');

@@ -36,4 +36,4 @@ socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data

server.on('connection', function (socket) {
socket.on('message', function () { });
socket.on('close', function () { });
socket.on('message', function(data){ });
socket.on('close', function(){ });
});

@@ -48,3 +48,3 @@ ```

server.on('connection', function (socket) {
server.on('connection', function(socket){
socket.send('hi');

@@ -54,6 +54,6 @@ });

// …
httpServer.on('upgrade', function (req, socket, head) {
httpServer.on('upgrade', function(req, socket, head){
server.handleUpgrade(req, socket, head);
});
httpServer.on('request', function (req, res) {
httpServer.on('request', function(req, res){
server.handleRequest(req, res);

@@ -69,5 +69,5 @@ });

var socket = new eio.Socket('ws://localhost/');
socket.on('open', function () {
socket.on('message', function (data) { });
socket.on('close', function () { });
socket.on('open', function(){
socket.on('message', function(data){});
socket.on('close', function(){});
});

@@ -77,19 +77,2 @@ </script>

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

@@ -100,4 +83,2 @@ [engine-client](http://github.com/learnboost/engine.io-client) repository.

- **Isomorphic with WebSocket.IO**. You can switch between a WebSocket server
and a multi-transport server by changing the `require`.
- **Maximum reliability**. Connections are established even in the presence of:

@@ -203,2 +184,11 @@ - proxies and load balancers.

packet (`25000`)
- `maxHttpBufferSize` (`Number`): how many bytes or characters a message
can be when polling, before closing the session (to avoid DoS). Default
value is `10E7`.
- `allowRequest` (`Function`): A function that receives a given handshake
or upgrade request as its first parameter, and can decide whether to
continue or not. The second argument is a function that needs to be
called with the decided information: `fn(err, success)`, where
`success` is a boolean value where false means that the request is
rejected, and err is an error code.
- `transports` (`<Array> String`): transports to allow connections

@@ -507,1 +497,2 @@ to (`['polling', 'websocket', 'flashsocket']`)

SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc