From 1e6999bb67e86d486da0b61f5bc71ed9f8417e65 Mon Sep 17 00:00:00 2001 From: Luigi Pinca Date: Thu, 25 Apr 2019 10:15:12 +0200 Subject: [PATCH] [major] Drop support for Node.js 6 --- .travis.yml | 1 - appveyor.yml | 1 - lib/websocket.js | 26 +++++++------------------- test/websocket.test.js | 2 -- 4 files changed, 7 insertions(+), 23 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1cf7887f6..96ffe98b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ node_js: - '11' - '10' - '8' - - '6' os: - linux - osx diff --git a/appveyor.yml b/appveyor.yml index a316bb770..d1f521e60 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -3,7 +3,6 @@ environment: - nodejs_version: '11' - nodejs_version: '10' - nodejs_version: '8' - - nodejs_version: '6' platform: - x86 matrix: diff --git a/lib/websocket.js b/lib/websocket.js index ce4317f4c..b7b704c84 100644 --- a/lib/websocket.js +++ b/lib/websocket.js @@ -1,12 +1,12 @@ 'use strict'; const EventEmitter = require('events'); -const crypto = require('crypto'); const https = require('https'); const http = require('http'); const net = require('net'); const tls = require('tls'); -const url = require('url'); +const { randomBytes, createHash } = require('crypto'); +const { URL } = require('url'); const PerMessageDeflate = require('./permessage-deflate'); const EventTarget = require('./event-target'); @@ -480,10 +480,7 @@ function initAsClient(websocket, address, protocols, options) { parsedUrl = address; websocket.url = address.href; } else { - // - // The WHATWG URL constructor is not available on Node.js < 6.13.0 - // - parsedUrl = url.URL ? new url.URL(address) : url.parse(address); + parsedUrl = new URL(address); websocket.url = address; } @@ -496,7 +493,7 @@ function initAsClient(websocket, address, protocols, options) { const isSecure = parsedUrl.protocol === 'wss:' || parsedUrl.protocol === 'https:'; const defaultPort = isSecure ? 443 : 80; - const key = crypto.randomBytes(16).toString('base64'); + const key = randomBytes(16).toString('base64'); const get = isSecure ? https.get : http.get; const path = parsedUrl.search ? `${parsedUrl.pathname || '/'}${parsedUrl.search}` @@ -588,9 +585,7 @@ function initAsClient(websocket, address, protocols, options) { req.abort(); - const addr = url.URL - ? new url.URL(location, address) - : url.resolve(address, location); + const addr = new URL(location, address); initAsClient(websocket, addr, protocols, options); } else if (!websocket.emit('unexpected-response', req, res)) { @@ -613,8 +608,7 @@ function initAsClient(websocket, address, protocols, options) { req = websocket._req = null; - const digest = crypto - .createHash('sha1') + const digest = createHash('sha1') .update(key + GUID) .digest('base64'); @@ -676,13 +670,7 @@ function initAsClient(websocket, address, protocols, options) { * @private */ function netConnect(options) { - // - // Override `options.path` only if `options` is a copy of the original options - // object. This is always true on Node.js >= 8 but not on Node.js 6 where - // `options.socketPath` might be `undefined` even if the `socketPath` option - // was originally set. - // - if (options.protocolVersion) options.path = options.socketPath; + options.path = options.socketPath; return net.connect(options); } diff --git a/test/websocket.test.js b/test/websocket.test.js index 6c23a15ea..f1e1b1746 100644 --- a/test/websocket.test.js +++ b/test/websocket.test.js @@ -37,8 +37,6 @@ describe('WebSocket', () => { }); it('accepts `url.URL` objects as url', function(done) { - if (!url.URL) return this.skip(); - const agent = new CustomAgent(); agent.addRequest = (req, opts) => {