Skip to content

Commit

Permalink
[major] Drop support for Node.js 6
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Apr 25, 2019
1 parent 5d751fb commit 1e6999b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -3,7 +3,6 @@ node_js:
- '11'
- '10'
- '8'
- '6'
os:
- linux
- osx
Expand Down
1 change: 0 additions & 1 deletion appveyor.yml
Expand Up @@ -3,7 +3,6 @@ environment:
- nodejs_version: '11'
- nodejs_version: '10'
- nodejs_version: '8'
- nodejs_version: '6'
platform:
- x86
matrix:
Expand Down
26 changes: 7 additions & 19 deletions 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');
Expand Down Expand Up @@ -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;
}

Expand All @@ -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}`
Expand Down Expand Up @@ -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)) {
Expand All @@ -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');

Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 0 additions & 2 deletions test/websocket.test.js
Expand Up @@ -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) => {
Expand Down

1 comment on commit 1e6999b

@julien-f
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Please sign in to comment.