cometd-nodejs-client
Advanced tools
Comparing version 1.0.4 to 1.1.0
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; |
{ | ||
"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" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
832
52344
3
11
8
+ Addedhttp-proxy-agent@^2.1.0
+ Addedhttps-proxy-agent@^2.1.0
+ Addedagent-base@4.3.0(transitive)
+ Addeddebug@3.1.0(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedes6-promisify@5.0.0(transitive)
+ Addedhttp-proxy-agent@2.1.0(transitive)
+ Addedhttps-proxy-agent@2.2.4(transitive)
+ Addedms@2.0.0(transitive)