Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

websocket13

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

websocket13 - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

105

lib/client.js

@@ -9,2 +9,3 @@ var WS13 = require('./index.js');

var Crypto = require('crypto');
var ProxyAgent = require('@doctormckay/proxy-agent');

@@ -105,3 +106,3 @@ const WEBSOCKET_VERSION = 13;

this._connectOptions.headers = this.headers;
this._connectOptions.agent = this._getConnectionAgent();
this._connectOptions.agent = ProxyAgent.getAgent(this.secure, this.options.httpProxy, this.options.proxyTimeout);

@@ -234,103 +235,1 @@ var req = (this.secure ? Https : Http).request(this._connectOptions, (res) => {

};
WebSocket.prototype._getConnectionAgent = function() {
if (!this.options.httpProxy) {
return false; // no need to use an agent
}
var wsOpts = this.options;
var wsSecure = this.secure;
var agent = new (this.secure ? Https : Http).Agent({"keepAlive": false});
agent.createConnection = function(options, callback) {
var url = parseUrl(wsOpts.httpProxy);
url.method = 'CONNECT';
url.path = options.host + ':' + options.port;
url.localAddress = options.localAddress;
url.localPort = options.localPort;
if (url.auth) {
url.headers = {
"Proxy-Authorization": "Basic " + (new Buffer(url.auth, 'utf8')).toString('base64')
};
delete url.auth;
}
// Make the CONNECT request
var finished = false;
var req = (url.protocol == "https:" ? Https : Http).request(url);
req.end();
req.setTimeout(wsOpts.proxyTimeout || 5000);
req.on('connect', (res, socket, head) => {
if (finished) {
// This has already errored
socket.end();
return;
}
finished = true;
req.setTimeout(0);
if (res.statusCode != 200) {
callback(new Error("Proxy CONNECT " + res.statusCode + " " + res.statusMessage));
return;
}
if (!wsSecure) {
// The WebSocket connection won't be secure, so we're done here
callback(null, socket);
return;
}
var tlsOptions = {"socket": socket};
for (var i in options) {
if (!options.hasOwnProperty(i)) {
continue;
}
if (i.match(/^_/) || ['agent', 'headers'].indexOf(i) != -1) {
// Ignore private properties, and "agent" and "headers"
continue;
}
tlsOptions[i] = options[i];
}
// The WebSocket connection needs to be secure, so do the TLS handshake with the WS server
var tlsSocket = TLS.connect(tlsOptions, () => {
if (!tlsSocket.authorized && tlsOptions.rejectUnauthorized !== false) {
// Checking this isn't strictly necessary as all versions of Node since 2013 won't call this callback in this case
callback(new Error(tlsSocket.authorizationError || "Secure connection failed"));
return;
}
// All good!
callback(null, tlsSocket);
});
tlsSocket.on('error', (err) => {
socket.end();
callback(err);
});
});
req.on('timeout', () => {
if (finished) {
return;
}
finished = true;
callback(new Error("Proxy connection timed out"));
});
req.on('error', (err) => {
if (finished) {
return;
}
finished = true;
callback(err);
});
};
return agent;
};

9

package.json
{
"name": "websocket13",
"version": "1.6.0",
"version": "1.6.1",
"description": "Simple WebSocket protocol 13 client with no native or heavy dependencies",

@@ -28,5 +28,6 @@ "author": "Alexander Corn <mckay@doctormckay.com>",

"dependencies": {
"bytebuffer": "^5.0.0",
"websocket-extensions": "^0.1.1",
"permessage-deflate": "^0.1.5"
"@doctormckay/proxy-agent": "^1.0.0",
"bytebuffer": "^5.0.1",
"permessage-deflate": "^0.1.5",
"websocket-extensions": "^0.1.1"
},

@@ -33,0 +34,0 @@ "engines": {

@@ -9,3 +9,3 @@ # WebSockets for Node.js

This is a pure-JavaScript implementation of [WebSockets version 13](https://tools.ietf.org/html/rfc6455).
It has only one lightweight dependency. It can establish connections to WebSocket servers (as a client), and also accept
It has no large or native dependencies. It can establish connections to WebSocket servers (as a client), and also accept
connections from clients (as a server).

@@ -18,5 +18,1 @@

Please see the [GitHub wiki](https://github.com/DoctorMcKay/node-websocket13/wiki) for documentation.
# Planned Features
- [Per-message compression](https://tools.ietf.org/html/draft-ietf-hybi-permessage-compression-28)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc