{
  "type": "module",
  "source": "doc/api/api-h2cclient.md",
  "modules": [
    {
      "textRaw": "Class: H2CClient",
      "name": "class:_h2cclient",
      "type": "module",
      "desc": "<p>Extends: <code>undici.Dispatcher</code></p>\n<p>A basic H2C client.</p>\n<p><strong>Example</strong></p>\n<pre><code class=\"language-js\">const { createServer } = require('node:http2')\nconst { once } = require('node:events')\nconst { H2CClient } = require('undici')\n\nconst server = createServer((req, res) => {\n  res.writeHead(200)\n  res.end('Hello, world!')\n})\n\nserver.listen()\nonce(server, 'listening').then(async () => {\n  const client = new H2CClient(`http://localhost:${server.address().port}/`)\n\n  const response = await client.request({ path: '/', method: 'GET' })\n  console.log(response.statusCode) // 200\n  response.body.text.then((text) => {\n    console.log(text) // Hello, world!\n  })\n})\n</code></pre>",
      "signatures": [
        {
          "textRaw": "`new H2CClient(url[, options])`",
          "name": "H2CClient",
          "type": "ctor",
          "params": [
            {
              "name": "url"
            },
            {
              "name": "options",
              "optional": true
            }
          ],
          "desc": "<p>Arguments:</p>\n<ul>\n<li><strong>url</strong> <code>URL | string</code> - Should only include the <strong>protocol, hostname, and port</strong>. It only supports <code>http</code> protocol.</li>\n<li><strong>options</strong> <code>H2CClientOptions</code> (optional)</li>\n</ul>\n<p>Returns: <code>H2CClient</code></p>",
          "modules": [
            {
              "textRaw": "Parameter: `H2CClientOptions`",
              "name": "parameter:_`h2cclientoptions`",
              "type": "module",
              "desc": "<ul>\n<li><strong>bodyTimeout</strong> <code>number | null</code> (optional) - Default: <code>300e3</code> - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use <code>0</code> to disable it entirely. Defaults to 300 seconds. Please note the <code>timeout</code> will be reset if you keep writing data to the socket everytime.</li>\n<li><strong>headersTimeout</strong> <code>number | null</code> (optional) - Default: <code>300e3</code> - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.</li>\n<li><strong>keepAliveMaxTimeout</strong> <code>number | null</code> (optional) - Default: <code>600e3</code> - The maximum allowed <code>keepAliveTimeout</code>, in milliseconds, when overridden by <em>keep-alive</em> hints from the server. Defaults to 10 minutes.</li>\n<li><strong>keepAliveTimeout</strong> <code>number | null</code> (optional) - Default: <code>4e3</code> - The timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by <em>keep-alive</em> hints from the server. See <a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives\">MDN: HTTP - Headers - Keep-Alive directives</a> for more details. Defaults to 4 seconds.</li>\n<li><strong>keepAliveTimeoutThreshold</strong> <code>number | null</code> (optional) - Default: <code>2e3</code> - A number of milliseconds subtracted from server <em>keep-alive</em> hints when overriding <code>keepAliveTimeout</code> to account for timing inaccuracies caused by e.g. transport latency. Defaults to 2 seconds.</li>\n<li><strong>maxHeaderSize</strong> <code>number | null</code> (optional) - Default: <code>--max-http-header-size</code> or <code>16384</code> - The maximum length of request headers in bytes. Defaults to Node.js' --max-http-header-size or 16KiB.</li>\n<li><strong>maxResponseSize</strong> <code>number | null</code> (optional) - Default: <code>-1</code> - The maximum length of response body in bytes. Set to <code>-1</code> to disable.</li>\n<li><strong>maxConcurrentStreams</strong>: <code>number</code> - Default: <code>100</code>. The maximum number of concurrent HTTP/2 streams per session — also advertised to the server as <code>peerMaxConcurrentStreams</code> (the cap on streams the server may push back). The initial value is replaced by the server's <code>SETTINGS_MAX_CONCURRENT_STREAMS</code> whenever the server sends one, so a user-supplied value acts as a pre-<code>SETTINGS</code> default rather than a hard cap.</li>\n<li><strong>pipelining</strong> <code>number | null</code> (optional) - Default to <code>maxConcurrentStreams</code> - The amount of concurrent requests sent over a single HTTP/2 session in accordance with <a href=\"https://httpwg.org/specs/rfc7540.html#StreamsLayer\">RFC-7540</a> Stream specification. Streams can be closed up by remote server at any time. Unlike on a regular <a href=\"/docs/docs/api/Client.html\"><code>Client</code></a>, <code>H2CClient</code> aliases <code>pipelining</code> to <code>maxConcurrentStreams</code> at construction time, so the two move together.</li>\n<li><strong>pingInterval</strong>: <code>number</code> - Default: <code>60e3</code>. The time interval in milliseconds between PING frames sent to the server. Set to <code>0</code> to disable PING frames. This is only applicable for HTTP/2 connections.</li>\n<li><strong>connect</strong> <code>ConnectOptions | null</code> (optional) - Default: <code>null</code>.</li>\n<li><strong>strictContentLength</strong> <code>Boolean</code> (optional) - Default: <code>true</code> - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body. <strong>Security Warning:</strong> Disabling this option can expose your application to HTTP Request Smuggling attacks, where mismatched content-length headers cause servers and proxies to interpret request boundaries differently. This can lead to cache poisoning, credential hijacking, and bypassing security controls. Only disable this in controlled environments where you fully trust the request source.</li>\n<li><strong>autoSelectFamily</strong>: <code>boolean</code> (optional) - Default: depends on local Node version, on Node 18.13.0 and above is <code>false</code>. Enables a family autodetection algorithm that loosely implements section 5 of <a href=\"https://tools.ietf.org/html/rfc8305#section-5\">RFC 8305</a>. See <a href=\"https://nodejs.org/api/net.html#socketconnectoptions-connectlistener\">here</a> for more details. This option is ignored if not supported by the current Node version.</li>\n<li><strong>autoSelectFamilyAttemptTimeout</strong>: <code>number</code> - Default: depends on local Node version, on Node 18.13.0 and above is <code>250</code>. The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the <code>autoSelectFamily</code> option. See <a href=\"https://nodejs.org/api/net.html#socketconnectoptions-connectlistener\">here</a> for more details.</li>\n</ul>",
              "modules": [
                {
                  "textRaw": "Parameter: `H2CConnectOptions`",
                  "name": "parameter:_`h2cconnectoptions`",
                  "type": "module",
                  "desc": "<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>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<li><strong>keepAlive</strong> <code>boolean | null</code> (optional) - Default: <code>true</code> - TCP keep-alive enabled</li>\n<li><strong>keepAliveInitialDelay</strong> <code>number | null</code> (optional) - Default: <code>60000</code> - TCP keep-alive interval for the socket in milliseconds</li>\n</ul>",
                  "displayName": "Parameter: `H2CConnectOptions`"
                }
              ],
              "displayName": "Parameter: `H2CClientOptions`"
            },
            {
              "textRaw": "Example - Basic Client instantiation",
              "name": "example_-_basic_client_instantiation",
              "type": "module",
              "desc": "<p>This will instantiate the undici H2CClient, but it will not connect to the origin until something is queued. Consider using <code>client.connect</code> to prematurely connect to the origin, or just call <code>client.request</code>.</p>\n<pre><code class=\"language-js\">\"use strict\";\nimport { H2CClient } from \"undici\";\n\nconst client = new H2CClient(\"http://localhost:3000\");\n</code></pre>",
              "displayName": "Example - Basic Client instantiation"
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "Instance Methods",
          "name": "instance_methods",
          "type": "module",
          "methods": [
            {
              "textRaw": "`H2CClient.close([callback])`",
              "name": "close",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Implements <a href=\"/docs/docs/api/Dispatcher.html#dispatcherclosecallback-promise\"><code>Dispatcher.close([callback])</code></a>.</p>"
            },
            {
              "textRaw": "`H2CClient.destroy([error, callback])`",
              "name": "destroy",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "error",
                      "optional": true
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>Implements <a href=\"/docs/docs/api/Dispatcher.html#dispatcherdestroyerror-callback-promise\"><code>Dispatcher.destroy([error, callback])</code></a>.</p>\n<p>Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided).</p>"
            },
            {
              "textRaw": "`H2CClient.connect(options[, callback])`",
              "name": "connect",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherconnectoptions-callback\"><code>Dispatcher.connect(options[, callback])</code></a>.</p>"
            },
            {
              "textRaw": "`H2CClient.dispatch(options, handlers)`",
              "name": "dispatch",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "handlers"
                    }
                  ]
                }
              ],
              "desc": "<p>Implements <a href=\"/docs/docs/api/Dispatcher.html#dispatcherdispatchoptions-handler\"><code>Dispatcher.dispatch(options, handlers)</code></a>.</p>"
            },
            {
              "textRaw": "`H2CClient.pipeline(options, handler)`",
              "name": "pipeline",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "handler"
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherpipelineoptions-handler\"><code>Dispatcher.pipeline(options, handler)</code></a>.</p>"
            },
            {
              "textRaw": "`H2CClient.request(options[, callback])`",
              "name": "request",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherrequestoptions-callback\"><code>Dispatcher.request(options [, callback])</code></a>.</p>"
            },
            {
              "textRaw": "`H2CClient.stream(options, factory[, callback])`",
              "name": "stream",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "factory"
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherstreamoptions-factory-callback\"><code>Dispatcher.stream(options, factory[, callback])</code></a>.</p>"
            },
            {
              "textRaw": "`H2CClient.upgrade(options[, callback])`",
              "name": "upgrade",
              "type": "method",
              "signatures": [
                {
                  "params": [
                    {
                      "name": "options"
                    },
                    {
                      "name": "callback",
                      "optional": true
                    }
                  ]
                }
              ],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#dispatcherupgradeoptions-callback\"><code>Dispatcher.upgrade(options[, callback])</code></a>.</p>"
            }
          ],
          "displayName": "Instance Methods"
        },
        {
          "textRaw": "Instance Properties",
          "name": "instance_properties",
          "type": "module",
          "properties": [
            {
              "textRaw": "`H2CClient.closed`",
              "name": "closed",
              "type": "property",
              "desc": "<ul>\n<li><code>boolean</code></li>\n</ul>\n<p><code>true</code> after <code>H2CClient.close()</code> has been called.</p>"
            },
            {
              "textRaw": "`H2CClient.destroyed`",
              "name": "destroyed",
              "type": "property",
              "desc": "<ul>\n<li><code>boolean</code></li>\n</ul>\n<p><code>true</code> after <code>client.destroyed()</code> has been called or <code>client.close()</code> has been called and the client shutdown has completed.</p>"
            },
            {
              "textRaw": "`H2CClient.pipelining`",
              "name": "pipelining",
              "type": "property",
              "desc": "<ul>\n<li><code>number</code></li>\n</ul>\n<p>Property to get and set the pipelining factor.</p>"
            }
          ],
          "displayName": "Instance Properties"
        },
        {
          "textRaw": "Instance Events",
          "name": "instance_events",
          "type": "module",
          "events": [
            {
              "textRaw": "Event: `'connect'`",
              "name": "connect",
              "type": "event",
              "params": [],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#event-connect\">Dispatcher Event: <code>'connect'</code></a>.</p>\n<p>Parameters:</p>\n<ul>\n<li><strong>origin</strong> <code>URL</code></li>\n<li><strong>targets</strong> <code>Array&#x3C;Dispatcher></code></li>\n</ul>\n<p>Emitted when a socket has been created and connected. The client will connect once <code>client.size > 0</code>.</p>",
              "modules": [
                {
                  "textRaw": "Example - Client connect event",
                  "name": "example_-_client_connect_event",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { createServer } from \"node:http2\";\nimport { H2CClient } from \"undici\";\nimport { once } from \"events\";\n\nconst server = createServer((request, response) => {\n  response.end(\"Hello, World!\");\n}).listen();\n\nawait once(server, \"listening\");\n\nconst client = new H2CClient(`http://localhost:${server.address().port}`);\n\nclient.on(\"connect\", (origin) => {\n  console.log(`Connected to ${origin}`); // should print before the request body statement\n});\n\ntry {\n  const { body } = await client.request({\n    path: \"/\",\n    method: \"GET\",\n  });\n  body.setEncoding(\"utf-8\");\n  body.on(\"data\", console.log);\n  client.close();\n  server.close();\n} catch (error) {\n  console.error(error);\n  client.close();\n  server.close();\n}\n</code></pre>",
                  "displayName": "Example - Client connect event"
                }
              ]
            },
            {
              "textRaw": "Event: `'disconnect'`",
              "name": "disconnect",
              "type": "event",
              "params": [],
              "desc": "<p>See <a href=\"/docs/docs/api/Dispatcher.html#event-disconnect\">Dispatcher Event: <code>'disconnect'</code></a>.</p>\n<p>Parameters:</p>\n<ul>\n<li><strong>origin</strong> <code>URL</code></li>\n<li><strong>targets</strong> <code>Array&#x3C;Dispatcher></code></li>\n<li><strong>error</strong> <code>Error</code></li>\n</ul>\n<p>Emitted when socket has disconnected. The error argument of the event is the error which caused the socket to disconnect. The client will reconnect if or once <code>client.size > 0</code>.</p>",
              "modules": [
                {
                  "textRaw": "Example - Client disconnect event",
                  "name": "example_-_client_disconnect_event",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { createServer } from \"node:http2\";\nimport { H2CClient } from \"undici\";\nimport { once } from \"events\";\n\nconst server = createServer((request, response) => {\n  response.destroy();\n}).listen();\n\nawait once(server, \"listening\");\n\nconst client = new H2CClient(`http://localhost:${server.address().port}`);\n\nclient.on(\"disconnect\", (origin) => {\n  console.log(`Disconnected from ${origin}`);\n});\n\ntry {\n  await client.request({\n    path: \"/\",\n    method: \"GET\",\n  });\n} catch (error) {\n  console.error(error.message);\n  client.close();\n  server.close();\n}\n</code></pre>",
                  "displayName": "Example - Client disconnect event"
                }
              ]
            },
            {
              "textRaw": "Event: `'drain'`",
              "name": "drain",
              "type": "event",
              "params": [],
              "desc": "<p>Emitted when pipeline is no longer busy.</p>\n<p>See <a href=\"/docs/docs/api/Dispatcher.html#event-drain\">Dispatcher Event: <code>'drain'</code></a>.</p>",
              "modules": [
                {
                  "textRaw": "Example - Client drain event",
                  "name": "example_-_client_drain_event",
                  "type": "module",
                  "desc": "<pre><code class=\"language-js\">import { createServer } from \"node:http2\";\nimport { H2CClient } from \"undici\";\nimport { once } from \"events\";\n\nconst server = createServer((request, response) => {\n  response.end(\"Hello, World!\");\n}).listen();\n\nawait once(server, \"listening\");\n\nconst client = new H2CClient(`http://localhost:${server.address().port}`);\n\nclient.on(\"drain\", () => {\n  console.log(\"drain event\");\n  client.close();\n  server.close();\n});\n\nconst requests = [\n  client.request({ path: \"/\", method: \"GET\" }),\n  client.request({ path: \"/\", method: \"GET\" }),\n  client.request({ path: \"/\", method: \"GET\" }),\n];\n\nawait Promise.all(requests);\n\nconsole.log(\"requests completed\");\n</code></pre>",
                  "displayName": "Example - Client drain event"
                }
              ]
            },
            {
              "textRaw": "Event: `'error'`",
              "name": "error",
              "type": "event",
              "params": [],
              "desc": "<p>Invoked for user errors such as throwing in the <code>onResponseError</code> handler.</p>"
            }
          ],
          "displayName": "Instance Events"
        }
      ],
      "displayName": "Class: H2CClient"
    }
  ]
}