From fe491c01811cebfeda091299cd97796904177c15 Mon Sep 17 00:00:00 2001 From: Quang Van Date: Fri, 18 Nov 2011 07:33:10 -0500 Subject: [PATCH 1/3] 'sys' renamed to 'util' for node 0.6.1 silent warning fix --- lib/websocket.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/websocket.js b/lib/websocket.js index aece46e..d21cb48 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -5,7 +5,11 @@ var events = require('events'); var http = require('http'); var net = require('net'); var urllib = require('url'); -var sys = require('sys'); +try{ + var sys = require('util'); +}catch(e){ + var sys = require('sys'); +} var FRAME_NO = 0; var FRAME_LO = 1; From b95c8e123bd1669f08cc1ae4c32c359127060926 Mon Sep 17 00:00:00 2001 From: alaingilbert Date: Wed, 16 Nov 2011 00:22:26 -0500 Subject: [PATCH 2/3] Fix the lib for v0.5 and v0.6 of nodejs. It's also backward compatible with v0.4 --- lib/websocket.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index aece46e..fbbb2e4 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -5,7 +5,7 @@ var events = require('events'); var http = require('http'); var net = require('net'); var urllib = require('url'); -var sys = require('sys'); +var sys = require('util'); var FRAME_NO = 0; var FRAME_LO = 1; @@ -470,10 +470,22 @@ var WebSocket = function(url, proto, opts) { // un-inspected to net.Stream.connect(). The latter accepts a // string as its first argument to connect to a UNIX socket. var httpClient = undefined; + var oldVersion = false; switch (getUrlScheme(url)) { case 'ws': var u = urllib.parse(url); - httpClient = http.createClient(u.port || 80, u.hostname); + var options = { + port: u.port || 80, + host: u.hostname, + path: u.path, + headers: httpHeaders + }; + if (+/^v0.([0-9]+).[0-9]+$/.exec(process.version)[1] <= 4) { + httpClient = http.createClient(u.port || 80, u.hostname); + oldVersion = true; + } else { + httpClient = http.request(options); + } httpPath = (u.pathname || '/') + (u.search || ''); httpHeaders.Host = u.hostname + (u.port ? (":" + u.port) : ""); break; @@ -581,7 +593,8 @@ var WebSocket = function(url, proto, opts) { errorListener(e); }); - var httpReq = httpClient.request(httpPath, httpHeaders); + if (oldVersion) { var httpReq = httpClient.request(httpPath, httpHeaders); } + else { var httpReq = httpClient; } httpReq.write(challenge, 'binary'); httpReq.end(); From 887e9bb6469c99c46e77fdc7e6878d0c7462850d Mon Sep 17 00:00:00 2001 From: Quang Van Date: Fri, 18 Nov 2011 08:54:02 -0500 Subject: [PATCH 3/3] oops forgot to removed previous empty, merge fixed after try/catch --- lib/websocket.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/websocket.js b/lib/websocket.js index 405bc73..e2b1895 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -488,9 +488,6 @@ var WebSocket = function(url, proto, opts) { }catch(e){ // node v0.4.x httpClient = http.createClient(u.port || 80, u.hostname); } - if (+/^v0.([0-9]+).[0-9]+$/.exec(process.version)[1] <= 4) { - } else { - } httpPath = (u.pathname || '/') + (u.search || ''); httpHeaders.Host = u.hostname + (u.port ? (":" + u.port) : ""); break;