The following examples demonstrate how to pass an hpagent instance to common HTTP libraries:
got
Pass the agent inside an agent object using the http key:
got('http://localhost:9200', {
agent: {
http: new HttpProxyAgent({
keepAlive: true,
proxy: 'http://localhost:8080'
})
}
})
needle
Pass the agent directly in the options object:
needle('get', 'http://localhost:9200', {
agent: new HttpProxyAgent({
keepAlive: true,
proxy: 'http://localhost:8080'
})
})
node-fetch
Pass the agent directly in the fetch options:
fetch('http://localhost:9200', {
agent: new HttpProxyAgent({
keepAlive: true,
proxy: 'http://localhost:8080'
})
})
simple-get
Pass the agent in the request object passed to .concat():
sget.concat({
url: 'http://localhost:9200',
agent: new HttpProxyAgent({
keepAlive: true,
proxy: 'https://localhost:8080'
})
}, function (err, response, data) {
// handle the response
})