hmpo-model
Advanced tools
Comparing version 4.0.4 to 4.1.0
@@ -125,24 +125,32 @@ 'use strict'; | ||
if (typeof proxy === 'string') proxy = { proxy }; | ||
if (typeof proxy === 'string') proxy = { uri: proxy }; | ||
const proxyUrl = new URL(proxy.uri); | ||
const getAuth = u => | ||
u.username && u.password ? decodeURIComponent(`${u.username}:${u.password}`) : | ||
u.username ? decodeURIComponent(u.username) : null; | ||
const getPath = u => u.pathname + u.search + u.hash; | ||
const options = Object.assign({ | ||
host: proxyUrl.hostname, | ||
port: proxyUrl.port, | ||
protocol: proxyUrl.protocol, | ||
path: getPath(proxyUrl), | ||
auth: getAuth(proxyUrl), | ||
maxSockets: 1, | ||
keepAlive: false | ||
}, proxy); | ||
const isHttps = (new URL(url).protocol === 'https:'); | ||
if (isHttps) { | ||
const { HttpsProxyAgent } = require('hpagent'); | ||
return { | ||
https: new HttpsProxyAgent(Object.assign({ | ||
keepAlive: false, | ||
maxSockets: 1, | ||
maxFreeSockets: 1, | ||
}, proxy)) | ||
}; | ||
const HttpsProxyAgent = require('https-proxy-agent'); | ||
const agent = new HttpsProxyAgent(options); | ||
return { https: agent }; | ||
} else { | ||
const { HttpProxyAgent } = require('hpagent'); | ||
return { | ||
http: new HttpProxyAgent(Object.assign({ | ||
keepAlive: false, | ||
maxSockets: 1, | ||
maxFreeSockets: 1, | ||
}, proxy)) | ||
}; | ||
const HttpProxyAgent = require('http-proxy-agent'); | ||
const agent = new HttpProxyAgent(options); | ||
return { http: agent }; | ||
} | ||
@@ -149,0 +157,0 @@ } |
{ | ||
"name": "hmpo-model", | ||
"version": "4.0.4", | ||
"version": "4.1.0", | ||
"description": "Simple model for interacting with http/rest apis.", | ||
@@ -30,3 +30,4 @@ "main": "index.js", | ||
"got": "^11.8.3", | ||
"hpagent": "^0.1.2", | ||
"http-proxy-agent": "^5.0.0", | ||
"https-proxy-agent": "^5.0.0", | ||
"lodash.kebabcase": "^4.1.1" | ||
@@ -33,0 +34,0 @@ }, |
@@ -7,1 +7,3 @@ let chai = require('chai'); | ||
chai.use(require('sinon-chai')); | ||
require('hmpo-logger').config(); |
@@ -8,3 +8,4 @@ 'use strict'; | ||
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent'); | ||
const HttpsProxyAgent = require('https-proxy-agent'); | ||
const HttpProxyAgent = require('http-proxy-agent'); | ||
@@ -75,3 +76,3 @@ describe('Remote Model', () => { | ||
it('should use console log and a trimHtml pass-through if hmpo-logger is not available', () => { | ||
logger.get.throws(new Error()); | ||
logger.get.throws({ message: 'test error' }); | ||
@@ -436,4 +437,5 @@ model = new Model(); | ||
'proxy': { | ||
proxy: 'http://proxy.example.com:8000', | ||
keepAlive: true | ||
uri: 'http://proxy.example.com:8000', | ||
keepAlive: true, | ||
maxSockets: 200 | ||
} | ||
@@ -445,3 +447,6 @@ }); | ||
http: { | ||
keepAlive: true | ||
proxy: { | ||
keepAlive: true, | ||
maxSockets: 200 | ||
} | ||
} | ||
@@ -451,2 +456,22 @@ } | ||
}); | ||
it('should process auth for the proxy', () => { | ||
let agent; | ||
agent = model.proxy('http://username:password@host:123/path', 'https://example.com'); | ||
sinon.assert.match(agent.https.proxy, { | ||
auth: 'username:password', | ||
host: 'host', | ||
port: 123, | ||
protocol: 'http:' | ||
}); | ||
agent = model.proxy('http://username@host:123/path', 'https://example.com'); | ||
sinon.assert.match(agent.https.proxy, { | ||
auth: 'username', | ||
host: 'host', | ||
port: 123, | ||
protocol: 'http:' | ||
}); | ||
}); | ||
}); | ||
@@ -750,3 +775,2 @@ | ||
model.request(settings, cb); | ||
console.log(model.logError.args[0][0]); | ||
model.logError.should.have.been.calledWithExactly({ | ||
@@ -753,0 +777,0 @@ settings: settings, |
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
72114
1652
5
4
+ Addedhttp-proxy-agent@^5.0.0
+ Addedhttps-proxy-agent@^5.0.0
+ Added@tootallnate/once@2.0.0(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedhttp-proxy-agent@5.0.0(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
- Removedhpagent@^0.1.2
- Removedhpagent@0.1.2(transitive)