-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[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
Conversation
test/websocket.test.js
Outdated
@@ -5,6 +5,7 @@ | |||
const assert = require('assert'); | |||
const crypto = require('crypto'); | |||
const https = require('https'); | |||
const { URL } = require('url'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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) { |
There was a problem hiding this comment.
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.
test/websocket.test.js
Outdated
@@ -361,6 +362,15 @@ describe('WebSocket', function () { | |||
|
|||
assert.strictEqual(ws.url, url); | |||
}); | |||
|
|||
if (URL) { | |||
it('accepts URL instances as url', function () { |
There was a problem hiding this comment.
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.
I think this can be merged. |
yeah, sorry, my internet decided to shit it self today :/ |
Addresses #1143