Compare commits

...

15 Commits
0.6 ... 0.6.0

Author SHA1 Message Date
Guillermo Rauch
4240385f6f Make sure to only write to open transports (thanks JohnDav) 2010-11-01 17:52:23 -03:00
Guillermo Rauch
22a93d06cb Another bad onClose call 2010-11-01 17:47:05 -03:00
Guillermo Rauch
4ea687b57e Ditto 2010-11-01 17:44:41 -03:00
Guillermo Rauch
227671d41d _open is still false, so destroy the connection immediately upon websocket error 2010-11-01 17:43:24 -03:00
Guillermo Rauch
7bf4ae1f05 Make sure .connection is not null on 'end' 2010-11-01 17:27:14 -03:00
Guillermo Rauch
b28d4288d5 Proper fix for invalid websocket key 2010-11-01 17:22:43 -03:00
Guillermo Rauch
835aee46bd Bump version 2010-11-01 17:20:50 -03:00
Guillermo Rauch
054e818bd9 Fix spooky bug 2010-11-01 17:20:23 -03:00
Guillermo Rauch
107806b304 Bump version 2010-11-01 17:10:52 -03:00
Guillermo Rauch
426795395c Call onclose after destroying the connection 2010-11-01 17:10:13 -03:00
Guillermo Rauch
df929876de Updated package.json 2010-11-01 16:54:15 -03:00
Guillermo Rauch
1002105f7a added onClose skipDisconnect flag 2010-11-01 16:34:37 -03:00
Guillermo Rauch
8f4f82a413 onClose call 2010-11-01 15:35:52 -03:00
Guillermo Rauch
e1745e20ac Make sure to disconnect directly onClose if the client is not handshaked and he can't possibly reconnect 2010-11-01 15:35:06 -03:00
Guillermo Rauch
681f004fe9 Make sure to clear the FD on end 2010-11-01 15:01:24 -03:00
7 changed files with 60 additions and 40 deletions

View File

@@ -63,8 +63,11 @@ Client.prototype._onConnect = function(req, res){
this.connection = req.connection;
this.connection.addListener('end', function(){
if (self.connection){
self.connection.end();
self.connection.destroy();
}
self._onClose();
self.connection.end();
});
if (req){
@@ -121,20 +124,25 @@ Client.prototype._onHeartbeat = function(h){
}
};
Client.prototype._onClose = function(){
Client.prototype._onClose = function(skipDisconnect){
if (this._open){
var self = this;
if ('_heartbeatInterval' in this) clearTimeout(this._heartbeatInterval);
if ('_heartbeatTimeout' in this) clearTimeout(this._heartbeatTimeout);
this._open = false;
this._disconnectTimeout = setTimeout(function(){
self._onDisconnect();
}, this.options.closeTimeout);
if (skipDisconnect !== false){
if (this.handshaked)
this._disconnectTimeout = setTimeout(function(){
self._onDisconnect();
}, this.options.closeTimeout);
else
this._onDisconnect();
}
}
};
Client.prototype._onDisconnect = function(){
if (this._open) this._onClose();
if (this._open) this._onClose(true);
if (this._disconnectTimeout) clearTimeout(this._disconnectTimeout);
if (this.connected){
this._writeQueue = [];

View File

@@ -41,5 +41,6 @@ HTMLFile.prototype._onConnect = function(req, res){
};
HTMLFile.prototype._write = function(message){
this.response.write('<script>parent.s._('+ JSON.stringify(message) +', document);</script>'); //json for escaping
if (this._open)
this.response.write('<script>parent.s._('+ JSON.stringify(message) +', document);</script>'); //json for escaping
};

View File

@@ -20,13 +20,15 @@ JSONPPolling.prototype._onConnect = function(req, res){
};
JSONPPolling.prototype._write = function(message){
if (this.request.headers.origin && !this._verifyOrigin(this.request.headers.origin)){
message = "alert('Cross domain security restrictions not met');";
} else {
message = "io.JSONP["+ this._index +"]._("+ JSON.stringify(message) +");";
if (this._open){
if (this.request.headers.origin && !this._verifyOrigin(this.request.headers.origin)){
message = "alert('Cross domain security restrictions not met');";
} else {
message = "io.JSONP["+ this._index +"]._("+ JSON.stringify(message) +");";
}
this.response.writeHead(200, {'Content-Type': 'text/javascript; charset=UTF-8', 'Content-Length': Buffer.byteLength(message)});
this.response.write(message);
this.response.end();
this._onClose();
}
this.response.writeHead(200, {'Content-Type': 'text/javascript; charset=UTF-8', 'Content-Length': Buffer.byteLength(message)});
this.response.write(message);
this.response.end();
this._onClose();
};

View File

@@ -19,6 +19,7 @@ WebSocket.prototype._onConnect = function(req, socket){
if (this.request.headers.upgrade !== 'WebSocket' || !this._verifyOrigin(this.request.headers.origin)){
this.listener.options.log('WebSocket connection invalid or Origin not verified');
this.connection.end();
this.connection.destroy();
return false;
}
@@ -55,7 +56,8 @@ WebSocket.prototype._onConnect = function(req, socket){
try {
this.connection.write(headers.concat('', '').join('\r\n'));
} catch(e){
this._onClose();
this.connection.end();
this.connection.destroy();
}
}
@@ -75,8 +77,12 @@ WebSocket.prototype._handle = function(data){
chunk = chunks[i];
if (chunk[0] !== '\u0000'){
this.listener.options.log('Data incorrectly framed by UA. Dropping connection');
this.connection.end();
this.connection.destroy();
if (this._open){
this._onClose();
} else {
this.connection.end();
this.connection.destroy();
}
return false;
}
this._onMessage(chunk.slice(1));
@@ -86,8 +92,9 @@ WebSocket.prototype._handle = function(data){
// http://www.whatwg.org/specs/web-apps/current-work/complete/network.html#opening-handshake
WebSocket.prototype._proveReception = function(headers){
var k1 = this.request.headers['sec-websocket-key1'],
k2 = this.request.headers['sec-websocket-key2'];
var self = this
, k1 = this.request.headers['sec-websocket-key1']
, k2 = this.request.headers['sec-websocket-key2'];
if (k1 && k2){
var md5 = crypto.createHash('md5');
@@ -97,11 +104,9 @@ WebSocket.prototype._proveReception = function(headers){
spaces = k.replace(/[^ ]/g, '').length;
if (spaces === 0 || n % spaces !== 0){
if (this.listener && this.listener.options){
this.listener.options.log('Invalid WebSocket key: "' + k + '". Dropping connection');
}
this.connection.end();
this.connection.destroy();
self.listener.options.log('Invalid WebSocket key: "' + k + '". Dropping connection');
self.connection.end();
self.connection.destroy();
return false;
}
@@ -119,7 +124,8 @@ WebSocket.prototype._proveReception = function(headers){
try {
this.connection.write(headers.concat('', '').join('\r\n') + md5.digest('binary'), 'binary');
} catch(e){
this._onClose();
this.connection.end();
this.connection.destroy();
}
}

View File

@@ -56,8 +56,9 @@ Multipart.prototype._onConnect = function(req, res){
};
Multipart.prototype._write = function(message){
this.response.write("Content-Type: text/plain" + (message.length === 1 && message.charCodeAt(0) === 6 ? "; charset=us-ascii" : "") + "\n\n");
this.response.write(message + "\n");
this.response.write("--socketio\n");
if ('flush' in this.response) this.response.flush();
if (this._open){
this.response.write("Content-Type: text/plain" + (message.length === 1 && message.charCodeAt(0) === 6 ? "; charset=us-ascii" : "") + "\n\n");
this.response.write(message + "\n");
this.response.write("--socketio\n");
}
};

View File

@@ -62,14 +62,16 @@ Polling.prototype._onClose = function(){
};
Polling.prototype._write = function(message){
var headers = {'Content-Type': 'text/plain; charset=UTF-8', 'Content-Length': Buffer.byteLength(message)};
// https://developer.mozilla.org/En/HTTP_Access_Control
if (this.request.headers.origin && this._verifyOrigin(this.request.headers.origin)){
headers['Access-Control-Allow-Origin'] = this.request.headers.origin;
if (this.request.headers.cookie) headers['Access-Control-Allow-Credentials'] = 'true';
if (this._open){
var headers = {'Content-Type': 'text/plain; charset=UTF-8', 'Content-Length': Buffer.byteLength(message)};
// https://developer.mozilla.org/En/HTTP_Access_Control
if (this.request.headers.origin && this._verifyOrigin(this.request.headers.origin)){
headers['Access-Control-Allow-Origin'] = this.request.headers.origin;
if (this.request.headers.cookie) headers['Access-Control-Allow-Credentials'] = 'true';
}
this.response.writeHead(200, headers);
this.response.write(message);
this.response.end();
this._onClose();
}
this.response.writeHead(200, headers);
this.response.write(message);
this.response.end();
this._onClose();
};

View File

@@ -1,6 +1,6 @@
{ "name" : "socket.io"
, "description" : "The cross-browser WebSocket"
, "version" : "0.6"
, "version" : "0.6.0"
, "author" : "LearnBoost"
, "licenses" :
[ { "type" : "MIT"