diff --git a/docs/api/Client.md b/docs/api/Client.md index f19c4081dd0..591fb97c44b 100644 --- a/docs/api/Client.md +++ b/docs/api/Client.md @@ -17,6 +17,8 @@ Returns: `Client` ### Parameter: `ClientOptions` +> ⚠️ Warning: The `H2` support is experimental. + * **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds. * **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds. * **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout` when overridden by *keep-alive* hints from the server. Defaults to 10 minutes. diff --git a/lib/client.js b/lib/client.js index bc717c36013..1c0f2d71494 100644 --- a/lib/client.js +++ b/lib/client.js @@ -90,6 +90,9 @@ const { } } = http2 +// Experimental +let h2ExperimentalWarned = false + const FastBuffer = Buffer[Symbol.species] const kClosedResolve = Symbol('kClosedResolve') @@ -344,9 +347,9 @@ class Client extends DispatcherBase { [kDispatch] (opts, handler) { const origin = opts.origin || this[kUrl].origin - let request - if (this[kHTTPConnVersion] === 'h2') request = Request[kHTTP2BuildRequest](origin, opts, handler) - else request = Request[kHTTP1BuildRequest](origin, opts, handler) + const request = this[kHTTPConnVersion] === 'h2' + ? Request[kHTTP2BuildRequest](origin, opts, handler) + : Request[kHTTP1BuildRequest](origin, opts, handler) this[kQueue].push(request) if (this[kResuming]) { @@ -1214,6 +1217,13 @@ async function connect (client) { const isH2 = socket.alpnProtocol === 'h2' if (isH2) { + if (!h2ExperimentalWarned) { + h2ExperimentalWarned = true + process.emitWarning('H2 support is experimental, expect them to change at any time.', { + code: 'UNDICI-H2' + }) + } + const session = http2.connect(client[kUrl], { createConnection: () => socket, peerMaxConcurrentStreams: client[kHTTP2SessionState].maxConcurrentStreams