Skip to content

Commit

Permalink
Restore support for default port numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Atkinson committed Feb 6, 2017
1 parent 66917d0 commit f043b52
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/WebSocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,7 @@ function initAsClient (address, protocols, options) {

const isSecure = serverUrl.protocol === 'wss:' || serverUrl.protocol === 'https:';
const key = crypto.randomBytes(16).toString('base64');
const port = serverUrl.port || (isSecure ? 443 : 80);
const httpObj = isSecure ? https : http;

//
Expand All @@ -559,7 +560,7 @@ function initAsClient (address, protocols, options) {

const requestOptions = {
host: serverUrl.hostname,
port: serverUrl.port,
port,
path: '/',
headers: {
'Sec-WebSocket-Version': options.protocolVersion,
Expand Down

3 comments on commit f043b52

@lpinca
Copy link
Member

@lpinca lpinca commented on f043b52 Feb 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nibbler999 why is this necessary? It will default to 443 or 80 if not specified.

@Nibbler999
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It defaults to null and throws a TypeError

const ws = new WebSocket('wss://echo.websocket.org/', { rejectUnauthorized: true });

TypeError: "port" option should be a number or string: null

@lpinca
Copy link
Member

@lpinca lpinca commented on f043b52 Feb 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha. That's weird though as

const opts = url.parse('http://example.com');
const req = http.request(opts);

should work.

Please sign in to comment.