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

WSS Support #30

Open
wants to merge 1 commit 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
19 changes: 10 additions & 9 deletions lib/websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var createSecretKey = function() {
// [0x21, 0x2f] (14 characters) and [0x3a, 0x7e] (68 characters)
var numChars = 1 + Math.floor(Math.random() * 12);
assert.ok(1 <= numChars && numChars <= 12);

for (var i = 0; i < numChars; i++) {
var pos = Math.floor(Math.random() * s.length + 1);

Expand Down Expand Up @@ -69,7 +69,7 @@ var createSecretKey = function() {

// Generate a challenge sequence
var createChallenge = function() {
var c = '';
var c = '';
for (var i = 0; i < 8; i++) {
c += String.fromCharCode(Math.floor(Math.random() * 255));
}
Expand All @@ -87,7 +87,7 @@ var secretKeyValue = function(sk) {

for (var i = 0; i < sk.length; i++) {
var cc = sk.charCodeAt(i);

if (cc == 0x20) {
ns++;
} else if (0x30 <= cc && cc <= 0x39) {
Expand All @@ -104,7 +104,7 @@ var secretKeyValue = function(sk) {
// byte string
var secretKeyHashValue = function(sk) {
var skv = secretKeyValue(sk);

var hv = '';
hv += String.fromCharCode((skv >> 24) & 0xff);
hv += String.fromCharCode((skv >> 16) & 0xff);
Expand All @@ -116,7 +116,7 @@ var secretKeyHashValue = function(sk) {

// Compute the secret key signature based on two secret key strings and some
// handshaking data.
var computeSecretKeySignature = function(s1, s2, hs) {
var computeSecretKeySignature = function(s1, s2, hs) {
assert.equal(hs.length, 8);

var hash = crypto.createHash('md5');
Expand All @@ -131,7 +131,7 @@ var computeSecretKeySignature = function(s1, s2, hs) {
// Return a hex representation of the given binary string; used for debugging
var str2hex = function(str) {
var hexChars = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f'
];

Expand Down Expand Up @@ -320,7 +320,7 @@ var WebSocket = function(url, proto, opts) {
if (serverClosed) {
serverCloseHandler();
}

if (consumed == 0) {
bufs.push(buf.slice(off, buf.length));
bufsBytes += buf.length - off;
Expand Down Expand Up @@ -431,7 +431,7 @@ var WebSocket = function(url, proto, opts) {

// Connect and perform handshaking with the server
(function() {
// Parse constructor arguments
// Parse constructor arguments
if (!url) {
throw new Error('Url and must be specified.');
}
Expand Down Expand Up @@ -470,7 +470,8 @@ 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;
switch (getUrlScheme(url)) {
var scheme = getUrlScheme(url).replace('wss', 'ws');
switch (scheme) {
case 'ws':
var u = urllib.parse(url);
httpClient = http.createClient(u.port || 80, u.hostname);
Expand Down