engine.io
Advanced tools
Comparing version 0.4.1 to 0.4.2
0.4.2 / 2013-02-08 | ||
================== | ||
* Only end upgrade socket connections if unhandled | ||
* Fix websocket dependency | ||
* Close socket if upgrade is received and socket.readyState != open | ||
0.4.1 / 2013-01-18 | ||
@@ -3,0 +10,0 @@ ================== |
@@ -41,3 +41,3 @@ /** | ||
/** | ||
* Expose mutable list of available trnasports. | ||
* Expose mutable list of available transports. | ||
* | ||
@@ -58,3 +58,3 @@ * @api public | ||
/** | ||
* Crates an http.Server exclusively used for WS upgrades. | ||
* Creates an http.Server exclusively used for WS upgrades. | ||
* | ||
@@ -102,2 +102,5 @@ * @param {Number} port | ||
var destroyUpgrade = (options.destroyUpgrade !== undefined) ? options.destroyUpgrade : true; | ||
var destroyUpgradeTimeout = options.destroyUpgradeTimeout || 1000; | ||
// normalize path | ||
@@ -132,3 +135,11 @@ path += '/'; | ||
} else if (false !== options.destroyUpgrade) { | ||
socket.end(); | ||
// default node behavior is to disconnect when no handlers | ||
// but by adding a handler, we prevent that | ||
// and if no eio thing handles the upgrade | ||
// then the socket needs to die! | ||
setTimeout(function() { | ||
if (socket.writable && socket.bytesWritten <= 0) { | ||
return socket.end(); | ||
} | ||
}, options.destroyUpgradeTimeout); | ||
} | ||
@@ -135,0 +146,0 @@ }); |
@@ -188,3 +188,3 @@ /** | ||
checkInterval = setInterval(check, 100); | ||
} else if ('upgrade' == packet.type) { | ||
} else if ('upgrade' == packet.type && self.readyState == 'open') { | ||
debug('got upgrade packet - upgrading'); | ||
@@ -191,0 +191,0 @@ self.upgraded = true; |
@@ -8,3 +8,3 @@ | ||
, parser = require('engine.io-parser') | ||
, debug = require('debug')('engine:polling') | ||
, debug = require('debug')('engine:polling'); | ||
@@ -11,0 +11,0 @@ /** |
{ | ||
"name": "engine.io" | ||
, "version": "0.4.1" | ||
, "version": "0.4.2" | ||
, "description": "The realtime engine behind Socket.IO. Provides the foundation of a bidirectional connection between client and server" | ||
@@ -19,3 +19,3 @@ , "main": "./lib/engine.io" | ||
"debug": "0.6.0" | ||
, "ws": "~0.4.21" | ||
, "ws": "0.4.25" | ||
, "engine.io-parser": "0.1.1" | ||
@@ -28,4 +28,3 @@ , "base64id": "0.1.0" | ||
, "superagent": "*" | ||
, "engine.io-client": "0.4.1" | ||
, "ws": "*" | ||
, "engine.io-client": "0.4.2" | ||
, "s": "*" | ||
@@ -32,0 +31,0 @@ } |
@@ -139,2 +139,3 @@ # Engine.IO: the realtime engine | ||
- `destroyUpgrade` (`Boolean`): destroy unhandled upgrade requests (`true`) | ||
- `destroyUpgradeTimeout` (`Number`): milliseconds after which unhandled requests are ended (`1000`) | ||
- **See Server options below for additional options you can pass** | ||
@@ -141,0 +142,0 @@ - **Returns** `Server` |
@@ -148,3 +148,3 @@ /*global eio,listen,request,expect*/ | ||
var server = http.createServer() | ||
, engine = eio.attach(server, { destroyUpgrade: false }); | ||
, engine = eio.attach(server, { destroyUpgrade: false, destroyUpgradeTimeout: 50 }); | ||
@@ -164,3 +164,3 @@ server.listen(function () { | ||
done(); | ||
}, 20); | ||
}, 100); | ||
@@ -176,2 +176,66 @@ function onEnd () { | ||
it('should destroy unhandled upgrades with after a timeout', function (done) { | ||
var server = http.createServer() | ||
, engine = eio.attach(server, { destroyUpgradeTimeout: 200 }); | ||
server.listen(function () { | ||
var client = net.createConnection(server.address().port); | ||
client.on('connect', function () { | ||
client.setEncoding('ascii'); | ||
client.write([ | ||
'GET / HTTP/1.1' | ||
, 'Upgrade: IRC/6.9' | ||
, '', '' | ||
].join('\r\n')); | ||
// send from client to server | ||
// tests that socket is still alive | ||
// this will not keep the socket open as the server does not handle it | ||
setTimeout(function() { | ||
client.write('foo'); | ||
}, 100); | ||
function onEnd () { | ||
done(); | ||
} | ||
client.on('end', onEnd); | ||
}); | ||
}); | ||
}); | ||
it('should not destroy handled upgrades with after a timeout', function (done) { | ||
var server = http.createServer() | ||
, engine = eio.attach(server, { destroyUpgradeTimeout: 100 }); | ||
// write to the socket to keep engine.io from closing it by writing before the timeout | ||
server.on('upgrade', function(req, socket) { | ||
socket.write('foo'); | ||
socket.on('data', function(chunk) { | ||
expect(chunk.toString()).to.be('foo'); | ||
socket.end(); | ||
}); | ||
}); | ||
server.listen(function () { | ||
var client = net.createConnection(server.address().port); | ||
client.on('connect', function () { | ||
client.setEncoding('ascii'); | ||
client.write([ | ||
'GET / HTTP/1.1' | ||
, 'Upgrade: IRC/6.9' | ||
, '', '' | ||
].join('\r\n')); | ||
// test that socket is still open by writing after the timeout period | ||
setTimeout(function() { | ||
client.write('foo'); | ||
}, 200); | ||
client.on('end', done); | ||
}); | ||
}); | ||
}); | ||
it('should preserve original request listeners', function (done) { | ||
@@ -178,0 +242,0 @@ var listeners = 0 |
@@ -1118,2 +1118,5 @@ /*global eio,eioc,listen,request,expect*/ | ||
}); | ||
// attach another engine to make sure it doesn't break upgrades | ||
var e2 = eio.attach(engine.httpServer, { path: '/foo' }); | ||
}); | ||
@@ -1120,0 +1123,0 @@ }); |
167053
5
4995
508
+ Addedcommander@0.6.1(transitive)
+ Addedws@0.4.25(transitive)
- Removedcommander@2.1.0(transitive)
- Removednan@1.0.0(transitive)
- Removedws@0.4.32(transitive)
Updatedws@0.4.25