Skip to content

Commit 1e6999b

Browse files
committedApr 25, 2019
[major] Drop support for Node.js 6
1 parent 5d751fb commit 1e6999b

File tree

4 files changed

+7
-23
lines changed

4 files changed

+7
-23
lines changed
 

‎.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ node_js:
33
- '11'
44
- '10'
55
- '8'
6-
- '6'
76
os:
87
- linux
98
- osx

‎appveyor.yml

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ environment:
33
- nodejs_version: '11'
44
- nodejs_version: '10'
55
- nodejs_version: '8'
6-
- nodejs_version: '6'
76
platform:
87
- x86
98
matrix:

‎lib/websocket.js

+7-19
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22

33
const EventEmitter = require('events');
4-
const crypto = require('crypto');
54
const https = require('https');
65
const http = require('http');
76
const net = require('net');
87
const tls = require('tls');
9-
const url = require('url');
8+
const { randomBytes, createHash } = require('crypto');
9+
const { URL } = require('url');
1010

1111
const PerMessageDeflate = require('./permessage-deflate');
1212
const EventTarget = require('./event-target');
@@ -480,10 +480,7 @@ function initAsClient(websocket, address, protocols, options) {
480480
parsedUrl = address;
481481
websocket.url = address.href;
482482
} else {
483-
//
484-
// The WHATWG URL constructor is not available on Node.js < 6.13.0
485-
//
486-
parsedUrl = url.URL ? new url.URL(address) : url.parse(address);
483+
parsedUrl = new URL(address);
487484
websocket.url = address;
488485
}
489486

@@ -496,7 +493,7 @@ function initAsClient(websocket, address, protocols, options) {
496493
const isSecure =
497494
parsedUrl.protocol === 'wss:' || parsedUrl.protocol === 'https:';
498495
const defaultPort = isSecure ? 443 : 80;
499-
const key = crypto.randomBytes(16).toString('base64');
496+
const key = randomBytes(16).toString('base64');
500497
const get = isSecure ? https.get : http.get;
501498
const path = parsedUrl.search
502499
? `${parsedUrl.pathname || '/'}${parsedUrl.search}`
@@ -588,9 +585,7 @@ function initAsClient(websocket, address, protocols, options) {
588585

589586
req.abort();
590587

591-
const addr = url.URL
592-
? new url.URL(location, address)
593-
: url.resolve(address, location);
588+
const addr = new URL(location, address);
594589

595590
initAsClient(websocket, addr, protocols, options);
596591
} else if (!websocket.emit('unexpected-response', req, res)) {
@@ -613,8 +608,7 @@ function initAsClient(websocket, address, protocols, options) {
613608

614609
req = websocket._req = null;
615610

616-
const digest = crypto
617-
.createHash('sha1')
611+
const digest = createHash('sha1')
618612
.update(key + GUID)
619613
.digest('base64');
620614

@@ -676,13 +670,7 @@ function initAsClient(websocket, address, protocols, options) {
676670
* @private
677671
*/
678672
function netConnect(options) {
679-
//
680-
// Override `options.path` only if `options` is a copy of the original options
681-
// object. This is always true on Node.js >= 8 but not on Node.js 6 where
682-
// `options.socketPath` might be `undefined` even if the `socketPath` option
683-
// was originally set.
684-
//
685-
if (options.protocolVersion) options.path = options.socketPath;
673+
options.path = options.socketPath;
686674
return net.connect(options);
687675
}
688676

‎test/websocket.test.js

-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ describe('WebSocket', () => {
3737
});
3838

3939
it('accepts `url.URL` objects as url', function(done) {
40-
if (!url.URL) return this.skip();
41-
4240
const agent = new CustomAgent();
4341

4442
agent.addRequest = (req, opts) => {

1 commit comments

Comments
 (1)

julien-f commented on Jun 3, 2019

@julien-f
Contributor

It would be nice to add a engines field in the package.json to better document this 🙂

Please sign in to comment.