Socket
Socket
Sign inDemoInstall

engine.io

Package Overview
Dependencies
75
Maintainers
1
Versions
147
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.2.1 to 0.2.2

7

History.md
0.2.2 / 2012-08-26
==================
* server: remove buffering for flash policy requests
* transport: avoid unhandled error events for stale transports (fixes #69)
* readme: documented `toString` behavior on `send` [EugenDueck]
0.2.1 / 2012-08-13

@@ -3,0 +10,0 @@ ==================

67

lib/server.js

@@ -14,3 +14,3 @@

, WebSocketServer = require('ws').Server
, debug = require('debug')('engine')
, debug = require('debug')('engine');

@@ -30,3 +30,3 @@ /**

function Server (opts) {
function Server(opts){
this.clients = {};

@@ -70,3 +70,3 @@ this.clientsCount = 0;

Server.prototype.upgrades = function (transport) {
Server.prototype.upgrades = function(transport){
if (!this.allowUpgrades) return [];

@@ -84,3 +84,3 @@ return transports[transport].upgradesTo || [];

Server.prototype.verify = function (req) {
Server.prototype.verify = function(req){
// transport check

@@ -106,12 +106,10 @@ var transport = req.query.transport;

* Prepares a request by processing the query string.
*
*
* @api private
*/
Server.prototype.prepare = function (req) {
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)
: {};
req.query = ~req.url.indexOf('?') ? qs.parse(parse(req.url).query) : {};
}

@@ -126,3 +124,3 @@ };

Server.prototype.id = function () {
Server.prototype.id = function(){
var rand = new Buffer(15);

@@ -143,3 +141,3 @@ this.sequenceNumber = (this.sequenceNumber + 1) | 0;

Server.prototype.close = function () {
Server.prototype.close = function(){
debug('closing all open clients');

@@ -160,3 +158,3 @@ for (var i in this.clients) {

Server.prototype.handleRequest = function (req, res) {
Server.prototype.handleRequest = function(req, res){
debug('handling "%s" http request "%s"', req.method, req.url);

@@ -190,3 +188,3 @@ this.prepare(req);

Server.prototype.handshake = function (transport, req) {
Server.prototype.handshake = function(transport, req){
var id = this.id();

@@ -196,8 +194,8 @@

var transport = new transports[transport](req)
, socket = new Socket(id, this, transport)
, self = this
var transport = new transports[transport](req);
var socket = new Socket(id, this, transport);
var self = this;
if (false !== this.cookie) {
transport.on('headers', function (headers) {
transport.on('headers', function(headers){
headers['Set-Cookie'] = self.cookie + '=' + id;

@@ -213,3 +211,3 @@ });

socket.once('close', function () {
socket.once('close', function(){
delete self.clients[id];

@@ -226,3 +224,3 @@ self.clientsCount--;

Server.prototype.handleUpgrade = function (req, socket, head) {
Server.prototype.handleUpgrade = function(req, socket, head){
this.prepare(req);

@@ -249,3 +247,3 @@

Server.prototype.onWebSocket = function (req, socket) {
Server.prototype.onWebSocket = function(req, socket){
if (!transports[req.query.transport].prototype.handlesUpgrades) {

@@ -289,27 +287,14 @@ debug('transport doesnt handle upgraded requests');

Server.prototype.handleSocket = function (socket) {
var chunks = ''
, buffer = false
socket.on('data', function onData (data) {
if (!buffer && 60 == data[0]) {
buffer = true;
} else {
socket.removeListener('data', onData);
return;
}
if (chunks.length < 23) {
chunks += data.toString('ascii');
}
if (chunks.length >= 23) {
if ('<policy-file-request/>\0' == chunks.substr(0, 23)) {
Server.prototype.handleSocket = function(socket){
socket.on('data', function onData(data){
// no need for buffering as node will discard subsequent packets
// since they constitute a malformed HTTP request
if (60 == data[0] && 23 == data.length) {
var str = data.slice(0, 23).toString();
if ('<policy-file-request/>\0' == str) {
socket.end(policy);
} else {
chunks = null;
socket.removeListener('data', onData);
}
}
socket.removeListener('data', onData);
});
};

@@ -8,3 +8,3 @@

, parser = require('./parser')
, debug = require('debug')('engine:transport')
, debug = require('debug')('engine:transport');

@@ -78,6 +78,10 @@ /**

Transport.prototype.onError = function (msg, desc) {
var err = new Error(msg);
err.type = 'TransportError';
err.description = desc;
this.emit('error', err);
if (this.listeners('error').length) {
var err = new Error(msg);
err.type = 'TransportError';
err.description = desc;
this.emit('error', err);
} else {
debug('ignored transport error %s (%s)', msg, desc);
}
};

@@ -84,0 +88,0 @@

{
"name": "engine.io"
, "version": "0.2.1"
, "version": "0.2.2"
, "description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server"
, "main": "./lib/engine.io"
, "author": "Guillermo Rauch <guillermo@learnboost.com>"
, "contributors": [
{ "name": "Eugen Dueck", "web": "https://github.com/EugenDueck" }
]
, "dependencies": {
"debug": "0.6.0"
, "engine.io-client": "0.2.1"
, "engine.io-client": "0.2.2"
, "ws": "~0.4.21"

@@ -10,0 +14,0 @@ }

@@ -225,3 +225,3 @@ # Engine.IO: the realtime engine

- **Arguments**
- `String`: utf-8 string
- `String`: unicode string
- `error`

@@ -249,5 +249,5 @@ - Fired when an error occurs.

- `send`:
- Sends a message.
- Sends a message, performing `message = toString(arguments[0])`.
- **Parameters**
- `String`: utf-8 string with outgoing data
- `String`: a string or any object implementing `toString()`, with outgoing data
- **Returns** `Socket` for chaining

@@ -254,0 +254,0 @@ - `close`

@@ -68,20 +68,2 @@

it('should respond to flash policy requests in parts', function (done) {
var server = http.createServer()
, engine = eio.attach(server);
server.listen(function () {
var client = net.createConnection(server.address().port);
client.write('<policy-file-request/>', function () {
client.write('\0');
client.setEncoding('ascii');
client.on('data', function (data) {
expect(data).to.contain('<allow-access-from');
client.end();
done();
});
});
});
});
it('should not respond to borked flash policy requests', function (done) {

@@ -88,0 +70,0 @@ var server = http.createServer()

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc