title: What is the role of https.Agent in Node?
body: <p>In the Node <a href="https://nodejs.org/api/https.html#https_https_request_url_options_callback" rel="noreferrer">https module docs</a>,
  regarding https.request, an example is shown:</p>
  <pre class="lang-js prettyprint-override"><code>const options = {
    hostname: 'encrypted.google.com',
    port: 443,
    path: '/',
    method: 'GET',
    key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
    cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
  };
  options.agent = new https.Agent(options);
  
  const req = https.request(options, (res) =&gt; {
    // ...
  });
  </code></pre>
  <p>This example is slightly ambiguous in my opinion, and I've asked an <a href="https://stackoverflow.com/questions/64076241/why-does-node-https-module-documentation-example-pass-tls-options-to-both-the-ag">SO question regarding this ambiguity</a> and following a comment reaffirming the strange wording, <a href="https://github.com/nodejs/node/issues/35360" rel="noreferrer">opened an issue for this</a>.</p>
  <p>Regardless, I am still trying to understand the part that the Agent plays in this scenario, seeing as the https.Agent module does accept TLS connection options:</p>
  <pre class="lang-ts prettyprint-override"><code>interface AgentOptions extends http.AgentOptions, tls.ConnectionOptions
  </code></pre>
  <p>The definition of the <a href="https://nodejs.org/api/https.html#https_class_https_agent" rel="noreferrer">https.Agent</a> object is:</p>
  <blockquote>
  <p>An Agent object for HTTPS similar to http.Agent.</p>
  </blockquote>
  <p>And the definition for the <a href="https://nodejs.org/api/http.html#http_class_http_agent" rel="noreferrer">http.Agent</a> object is:</p>
  <blockquote>
  <p>An Agent is responsible for managing connection persistence and reuse for HTTP clients.</p>
  </blockquote>
  <p>From this I understand that an Agent is 'in charge' of managing a connection - and clearly, the fact that https.Agent exists on top of the 'plain' http.Agent exists would imply that it is 'in charge' of managing an HTTPS connection - hence the TLS configuration options it may receive.</p>
  <p>My question is this - does this mean that the Agent in this case has an added responsibility of configuring the network security of the requests? this is a strange API if this is true - I would have expected to see the network connection config on a separate key for the https.request (as is shown in the example after the snippet above). Why overload the same object for another responsibility? Really, why have an https.Agent at all? The http.Agent should control connection pooling and keeping connections alive, while another layer should control configuring the actual requests. The https.Agent object doesn't seem well-defined to me.</p>