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

hmpo-model

Package Overview
Dependencies
Maintainers
3
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hmpo-model - npm Package Compare versions

Comparing version 4.0.4 to 4.1.0

42

lib/remote-model.js

@@ -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,

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