Skip to content

Commit

Permalink
feat: add experimental warning
Browse files Browse the repository at this point in the history
  • Loading branch information
metcoder95 committed Aug 23, 2023
1 parent 224c26e commit 904f334
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 13 additions & 3 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ const {
}
} = http2

// Experimental
let h2ExperimentalWarned = false

const FastBuffer = Buffer[Symbol.species]

const kClosedResolve = Symbol('kClosedResolve')
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 904f334

Please sign in to comment.