It seems to me that it's rather uncommon for people to use their own http.Agent instances, but I'm creating a system with trusted peers and I found the existing docs to be unclear.
I have some questions here and if there is someone who understands that code well willing to answer me, I'd much appreciate it.
https://github.com/joyent/node/issues/8412Certainly I want to be reusing the agent and some of the parameters don't need to / shouldn't be specified in the request each time.
After poking around the docs and code a bit I'm guessing that the example should be more like this:
var agent = new https.Agent({
ca: [fs.readFileSync('test/fixtures/keys/agent2-ca.pem')]
, key: fs.readFileSync('test/fixtures/keys/agent2-key.pem')
, cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
, maxSockets: 256
});
var req1 = https.request({
agent: agent
, method: 'GET'
, hostname: '
site-a.example.com'
, port: 443
, path: '/one-thing'
}, function(res) {
...
}
var req1 = https.request({
agent: agent
, method: 'GET'
, hostname: '
site-b.example.com'
, port: 443
, path: '/two-thing'
}, function(res) {
...
}
Or perhaps like this:
var agent = new https.Agent({ maxSockets: 256 });
var req1 = https.request({
agent: agent
, method: 'GET'
, hostname: '
site-a.example.com'
, port: 443
, path: '/one-thing'
, ca: [fs.readFileSync('test/fixtures/keys/agent2-ca.pem')]
, key: fs.readFileSync('test/fixtures/keys/agent2-key.pem')
, cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
}, function(res) {
...
}
var req1 = https.request({
agent: agent
, method: 'GET'
, hostname: '
site-b.example.com'
, port: 443
, path: '/two-thing'
, ca: [fs.readFileSync('test/fixtures/keys/agent2-ca.pem')]
, key: fs.readFileSync('test/fixtures/keys/agent2-key.pem')
, cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
}, function(res) {
...
}
Or maybe even
var agent = new https.Agent({
maxSockets: 256
, hostname: '
site-b.example.com'
, port: 443
, ca: [fs.readFileSync('test/fixtures/keys/agent2-ca.pem')]
, key: fs.readFileSync('test/fixtures/keys/agent2-key.pem')
, cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
});
var req1 = https.request({
agent: agent
, method: 'GET'
, path: '/one-thing'
}, function(res) {
...
}
var req1 = https.request({
agent: agent
, method: 'GET'
, path: '/two-thing'
}, function(res) {
...
}