Skip to content
This repository has been archived by the owner on Mar 30, 2022. It is now read-only.

Combine Node0.6 fix from alaingilbert #21

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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){ // node v0.4.x
var sys = require('sys');
}

var FRAME_NO = 0;
var FRAME_LO = 1;
Expand Down Expand Up @@ -473,7 +477,17 @@ var WebSocket = function(url, proto, opts) {
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
};
try{
httpClient = http.request(options);
}catch(e){ // node v0.4.x
httpClient = http.createClient(u.port || 80, u.hostname);
}
httpPath = (u.pathname || '/') + (u.search || '');
httpHeaders.Host = u.hostname + (u.port ? (":" + u.port) : "");
break;
Expand Down Expand Up @@ -581,7 +595,11 @@ var WebSocket = function(url, proto, opts) {
errorListener(e);
});

var httpReq = httpClient.request(httpPath, httpHeaders);
try{ // node v0.4.x
var httpReq = httpClient.request(httpPath, httpHeaders);
}catch(e){
var httpReq = httpClient;
}

httpReq.write(challenge, 'binary');
httpReq.end();
Expand Down