Skip to content

[fix] Allow URL instances as URL for WebSocket constructors #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 16, 2018

Conversation

3rd-Eden
Copy link
Member

Addresses #1143

@@ -5,6 +5,7 @@
const assert = require('assert');
const crypto = require('crypto');
const https = require('https');
const { URL } = require('url');
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't work on Node.js 4.

Copy link
Member Author

Choose a reason for hiding this comment

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

Node 4 doesn't have the URL instance either, so I've opted for adding in some horrible if statements in the test suite :/

lib/websocket.js Outdated

const serverUrl = url.parse(address);
let serverUrl;
Copy link
Member

Choose a reason for hiding this comment

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

We are still using var when const can not be used.

Copy link
Member Author

Choose a reason for hiding this comment

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

FML, I've been writing to much ES6.

@lpinca
Copy link
Member

lpinca commented Mar 15, 2018

if (serverUrl.auth) requestOptions.auth = serverUrl.auth;

No longer works when using a WHATWG URL and similarly:

} else if (serverUrl.path) {

lib/websocket.js Outdated
@@ -511,6 +519,9 @@ function initAsClient (address, protocols, options) {
}
if (options.host) requestOptions.headers.Host = options.host;
if (serverUrl.auth) requestOptions.auth = serverUrl.auth;
else if (serverUrl.username && serverUrl.password) {
Copy link
Member

Choose a reason for hiding this comment

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

Still not enough I think:

var u = new url.URL('ws://[email protected]')
undefined
> u
URL {
  href: 'ws://[email protected]/',
  origin: 'ws://example.org',
  protocol: 'ws:',
  username: 'foo',
  password: '',
  host: 'example.org',
  hostname: 'example.org',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: '' }

auth should be 'foo' but it doesn't get set as serverUrl.password is falsy.

@@ -361,6 +362,15 @@ describe('WebSocket', function () {

assert.strictEqual(ws.url, url);
});

if (URL) {
it('accepts URL instances as url', function () {
Copy link
Member

@lpinca lpinca Mar 15, 2018

Choose a reason for hiding this comment

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

I would use this.skip() for consistency if WHATWG URL is not supported.

@lpinca
Copy link
Member

lpinca commented Mar 16, 2018

I think this can be merged.

@lpinca lpinca merged commit 1504d67 into master Mar 16, 2018
@lpinca lpinca deleted the issue-1143 branch March 16, 2018 14:02
@3rd-Eden
Copy link
Member Author

yeah, sorry, my internet decided to shit it self today :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants