Permalink
Browse files

sync to ws upstream

  • Loading branch information...
2 parents a07853d + 6a6b4ef commit 27af9b7a70a39d38b9e6a296628694d97a05a3c0 tom zhou committed Apr 9, 2013
Showing with 11 additions and 8 deletions.
  1. +6 −7 lib/WebSocket.js
  2. +5 −1 lib/WebSocketServer.js
View
@@ -410,7 +410,6 @@ function initAsClient(address, options) {
protocolVersion: protocolVersion,
host: null,
protocol: null,
-
// ssl-related options
pfx: null,
key: null,
@@ -480,28 +479,28 @@ function initAsClient(address, options) {
if (isNodeV4) {
throw new Error('Client side certificates are not supported on Node 0.4.x');
}
-
+
requestOptions.pfx = options.value.pfx;
requestOptions.key = options.value.key;
requestOptions.passphrase = options.value.passphrase;
requestOptions.cert = options.value.cert;
requestOptions.ca = options.value.ca;
requestOptions.ciphers = options.value.ciphers;
requestOptions.rejectUnauthorized = options.value.rejectUnauthorized;
-
+
// global agent ignores client side certificates
agent = new httpObj.Agent(requestOptions);
}
-
+
if (isNodeV4) {
requestOptions.path = (serverUrl.pathname || '/') + (serverUrl.search || '');
}
else requestOptions.path = serverUrl.path || '/';
-
+
if (agent) {
requestOptions.agent = agent;
}
-
+
if (isUnixSocket) {
requestOptions.socketPath = serverUrl.pathname;
}
@@ -678,6 +677,7 @@ function cleanupWebsocketResources(error) {
this.readyState = WebSocket.CLOSED;
clearTimeout(this._closeTimer);
+ if (emitClose) this.emit('close', this._closeCode || 1000, this._closeMessage || '');
if (this._socket) {
removeAllListeners(this._socket);
@@ -701,7 +701,6 @@ function cleanupWebsocketResources(error) {
this._receiver.cleanup();
this._receiver = null;
}
- if (emitClose) this.emit('close', this._closeCode || 1000, this._closeMessage || '');
removeAllListeners(this);
this.on('error', function() {}); // catch all errors after this
delete this._queue;
@@ -84,7 +84,11 @@ function WebSocketServer(options, callback) {
self.emit('error', error)
});
this._server.on('upgrade', function(req, socket, upgradeHead) {
- self.handleUpgrade(req, socket, upgradeHead, function(client) {
+ //copy upgradeHead to avoid retention of large slab buffers used in node core
+ var head = new Buffer(upgradeHead.length);
+ upgradeHead.copy(head);
+
+ self.handleUpgrade(req, socket, head, function(client) {
self.emit('connection'+req.url, client);
self.emit('connection', client);
});

0 comments on commit 27af9b7

Please sign in to comment.