{
  "type": "module",
  "source": "doc/api/api-connector.md",
  "modules": [
    {
      "textRaw": "Connector",
      "name": "connector",
      "type": "module",
      "desc": "<p>Undici creates the underlying socket via the connector builder.\nNormally, this happens automatically and you don't need to care about this,\nbut if you need to perform some additional check over the currently used socket,\nthis is the right place.</p>\n<p>If you want to create a custom connector, you must import the <code>buildConnector</code> utility.</p>",
      "modules": [
        {
          "textRaw": "Parameter: `buildConnector.BuildOptions`",
          "name": "parameter:_`buildconnector.buildoptions`",
          "type": "module",
          "desc": "<p>Every Tls option, see <a href=\"https://nodejs.org/api/tls.html#tls_tls_connect_options_callback\">here</a>.\nFurthermore, the following options can be passed:</p>\n<ul>\n<li><strong>socketPath</strong> <code>string | null</code> (optional) - Default: <code>null</code> - An IPC endpoint, either Unix domain socket or Windows named pipe.</li>\n<li><strong>preferH2</strong> <code>boolean</code> (optional) - Default: <code>false</code> - Only effective together with <code>allowH2</code>. When <code>true</code>, ALPN is offered as <code>['h2', 'http/1.1']</code> (HTTP/2 first) instead of the default <code>['http/1.1', 'h2']</code>. Use this when the server selects the ALPN protocol by <em>client</em> preference (e.g. some load balancers) so that HTTP/2 is negotiated whenever the server supports it. If the server does not support HTTP/2, ALPN transparently falls back to <code>http/1.1</code>.</li>\n<li><strong>maxCachedSessions</strong> <code>number | null</code> (optional) - Default: <code>100</code> - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: <code>100</code>.</li>\n<li><strong>timeout</strong> <code>number | null</code> (optional) -  In milliseconds. Default <code>10e3</code>.</li>\n<li><strong>servername</strong> <code>string | null</code> (optional)</li>\n</ul>\n<p>Once you call <code>buildConnector</code>, it will return a connector function, which takes the following parameters.</p>",
          "displayName": "Parameter: `buildConnector.BuildOptions`"
        },
        {
          "textRaw": "Parameter: `connector.Options`",
          "name": "parameter:_`connector.options`",
          "type": "module",
          "desc": "<ul>\n<li><strong>hostname</strong> <code>string</code> (required)</li>\n<li><strong>host</strong> <code>string</code> (optional)</li>\n<li><strong>protocol</strong> <code>string</code> (required)</li>\n<li><strong>port</strong> <code>string</code> (required)</li>\n<li><strong>servername</strong> <code>string</code> (optional)</li>\n<li><strong>localAddress</strong> <code>string | null</code> (optional) Local address the socket should connect from.</li>\n<li><strong>httpSocket</strong> <code>Socket</code> (optional) Establish secure connection on a given socket rather than creating a new socket. It can only be sent on TLS update.</li>\n</ul>",
          "displayName": "Parameter: `connector.Options`"
        },
        {
          "textRaw": "Basic example",
          "name": "basic_example",
          "type": "module",
          "desc": "<pre><code class=\"language-js\">'use strict'\n\nimport { Client, buildConnector } from 'undici'\n\nconst connector = buildConnector({ rejectUnauthorized: false })\nconst client = new Client('https://localhost:3000', {\n  connect (opts, cb) {\n    connector(opts, (err, socket) => {\n      if (err) {\n        cb(err)\n      } else if (/* assertion */) {\n        socket.destroy()\n        cb(new Error('kaboom'))\n      } else {\n        cb(null, socket)\n      }\n    })\n  }\n})\n</code></pre>",
          "displayName": "Basic example"
        },
        {
          "textRaw": "Example: validate the CA fingerprint",
          "name": "example:_validate_the_ca_fingerprint",
          "type": "module",
          "desc": "<pre><code class=\"language-js\">'use strict'\n\nimport { Client, buildConnector } from 'undici'\n\nconst caFingerprint = 'FO:OB:AR'\nconst connector = buildConnector({ rejectUnauthorized: false })\nconst client = new Client('https://localhost:3000', {\n  connect (opts, cb) {\n    connector(opts, (err, socket) => {\n      if (err) {\n        cb(err)\n      } else if (getIssuerCertificate(socket).fingerprint256 !== caFingerprint) {\n        socket.destroy()\n        cb(new Error('Fingerprint does not match or malformed certificate'))\n      } else {\n        cb(null, socket)\n      }\n    })\n  }\n})\n\nclient.request({\n  path: '/',\n  method: 'GET'\n}, (err, data) => {\n  if (err) throw err\n\n  const bufs = []\n  data.body.on('data', (buf) => {\n    bufs.push(buf)\n  })\n  data.body.on('end', () => {\n    console.log(Buffer.concat(bufs).toString('utf8'))\n    client.close()\n  })\n})\n\nfunction getIssuerCertificate (socket) {\n  let certificate = socket.getPeerCertificate(true)\n  while (certificate &#x26;&#x26; Object.keys(certificate).length > 0) {\n    // invalid certificate\n    if (certificate.issuerCertificate == null) {\n      return null\n    }\n\n    // We have reached the root certificate.\n    // In case of self-signed certificates, `issuerCertificate` may be a circular reference.\n    if (certificate.fingerprint256 === certificate.issuerCertificate.fingerprint256) {\n      break\n    }\n\n    // continue the loop\n    certificate = certificate.issuerCertificate\n  }\n  return certificate\n}\n</code></pre>",
          "displayName": "Example: validate the CA fingerprint"
        }
      ],
      "displayName": "Connector"
    }
  ]
}