Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
hpagent-catchfix
Advanced tools
A ready to use http and https agent for working with proxies that keeps connections alive!
A ready to use http and https agent for working with proxies that keeps connections alive!
npm install hpagent
Based on your infrastructure, you should use the http agent or the https agent. The following table will help you picking the right one.
Type | Proxy | Server |
---|---|---|
HttpProxyAgent | HTTP | HTTP |
HttpProxyAgent | HTTPS | HTTP |
HttpsProxyAgent | HTTP | HTTPS |
HttpsProxyAgent | HTTPS | HTTPS |
const { HttpProxyAgent, HttpsProxyAgent } = require('hpagent')
Once you have understood the right agent for your use case, you can instance it. It takes the same parameter of the Node.js core's http(s) agent and an additional proxy
option, which is the url of your proxy.
const http = require('http')
const { HttpProxyAgent } = require('hpagent')
const agent = new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: 'http://localhost:8080'
})
http.get('http://localhost:9200', { agent })
.on('response', console.log)
.end()
If your proxy requires basic authentication, you can configure it in the proxy url:
const http = require('http')
const { HttpProxyAgent } = require('hpagent')
const agent = new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: 'http://user:pwd@localhost:8080'
})
http.get('http://localhost:9200', { agent })
.on('response', console.log)
.end()
You can also pass custom options intended only for the proxy CONNECT request with the proxyConnectOptions
option,
such as headers or tls.connect()
options:
const fs = require('fs')
const http = require('http')
const { HttpProxyAgent } = require('hpagent')
const agent = new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
proxy: 'https://localhost:8080',
proxyConnectOptions: {
headers: {
'Proxy-Authorization': 'Basic YWxhZGRpbjpvcGVuc2VzYW1l',
},
ca: [ fs.readFileSync('custom-proxy-cert.pem') ]
}
})
http.get('http://localhost:9200', { agent })
.on('response', console.log)
.end()
Following you can find the list of userland http libraries that are tested with this agent.
got('http://localhost:9200', {
agent: {
http: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: 'http://localhost:8080'
})
}
})
needle('get', 'http://localhost:9200', {
agent: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: 'http://localhost:8080'
})
})
fetch('http://localhost:9200', {
agent: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: 'http://localhost:8080'
})
})
sget.concat({
url: `http://${server.address().address}:${server.address().port}`,
agent: new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 1000,
maxSockets: 256,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: `https://${proxy.address().address}:${proxy.address().port}`
})
}, function (err, response, data) {
// handle the response
})
This software is licensed under the MIT.
FAQs
A ready to use http and https agent for working with proxies that keeps connections alive!
We found that hpagent-catchfix demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.