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

cometd-nodejs-client

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cometd-nodejs-client - npm Package Compare versions

Comparing version 1.0.4 to 1.1.0

test/proxy.js

59

cometd-nodejs-client.js
module.exports = {
adapt: function() {
adapt: function(options) {
var url = require('url');
var httpc = require('http');
var https = require('https');
var HttpcProxyAgent = require('http-proxy-agent');
var HttpsProxyAgent = require('https-proxy-agent');

@@ -19,10 +21,18 @@ var window = global['window'];

// Fields shared by all XMLHttpRequest instances.
var _agentc = new httpc.Agent({
var _agentOptions = {
keepAlive: true
});
var _agents = new https.Agent({
keepAlive: true
});
};
var _agentc = new httpc.Agent(_agentOptions);
var _agents = new https.Agent(_agentOptions);
var _globalCookies = {};
var _logLevel = options && options.logLevel || 'info';
function _debug() {
if (_logLevel === 'debug') {
console.log.apply(this, Array.from(arguments));
}
}
function _secure(uri) {

@@ -70,2 +80,37 @@ return /^https/i.test(uri.protocol);

function _chooseAgent(serverURI) {
var serverHostPort = serverURI.host;
var proxy = options && options.httpProxy && options.httpProxy.uri;
if (proxy) {
var isIncluded = true;
var includes = options.httpProxy.includes;
if (includes && Array.isArray(includes)) {
isIncluded = false;
for (var i = 0; i < includes.length; ++i) {
if (new RegExp(includes[i]).test(serverHostPort)) {
isIncluded = true;
break;
}
}
}
if (isIncluded) {
var excludes = options.httpProxy.excludes;
if (excludes && Array.isArray(excludes)) {
for (var e = 0; e < excludes.length; ++e) {
if (new RegExp(excludes[e]).test(serverHostPort)) {
isIncluded = false;
break;
}
}
}
}
if (isIncluded) {
_debug('proxying', serverURI.href, 'via', proxy);
var agentOpts = Object.assign(url.parse(proxy), _agentOptions);
return _secure(serverURI) ? new HttpsProxyAgent(agentOpts) : new HttpcProxyAgent(agentOpts);
}
}
return _secure(serverURI) ? _agents : _agentc;
}
this.status = 0;

@@ -78,4 +123,4 @@ this.statusText = '';

_config = url.parse(uri);
_config.agent = _chooseAgent(_config);
_config.method = method;
_config.agent = _secure(_config) ? _agents : _agentc;
_config.headers = {};

@@ -82,0 +127,0 @@ this.readyState = window.XMLHttpRequest.OPENED;

8

package.json
{
"name": "cometd-nodejs-client",
"version": "1.0.4",
"version": "1.1.0",
"description": "Adapter code to run the CometD JavaScript library in a NodeJS environment",

@@ -24,7 +24,9 @@ "keywords": [

"dependencies": {
"cometd": ">=3.1.2"
"cometd": ">=3.1.2",
"http-proxy-agent": "^2.1.0",
"https-proxy-agent": "^2.1.0"
},
"devDependencies": {
"mocha": "*"
"mocha": "^6.2.2"
}
}
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