Skip to content

Commit 157044a

Browse files
Reflexclaude
andcommitted
docs(http2): clarify transport comments and drop stale undici references
Addresses PR review: - Clarify the `src/lib/http2-transport.ts` header: explain that transport selection matters only on Node (its default `node-fetch` speaks HTTP/1.1), while browsers/Deno/Bun already negotiate HTTP/2 via the platform fetch. - Clarify the `http2` option JSDoc: "Node.js only" distinguishes it from other JS runtimes, where the option has no effect. - Remove stale undici references now that the H2 transport is native `node:http2`: the `makeHttp2Fetch` shim docs (Node = `node:http2`, arg is H2FetchOptions), the web/Deno no-op comments, the "Replaces undici" note, and the undici-based rationale in the README requirements. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent b87b790 commit 157044a

8 files changed

Lines changed: 28 additions & 24 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ TypeScript >= 4.5 is supported.
398398
The following runtimes are supported:
399399

400400
- Web browsers (Up-to-date Chrome, Firefox, Safari, Edge, and more)
401-
- Node.js 20.18.1 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions. (Raised from 18 because the SDK now depends on undici 7 on Node; the HTTP/2 transport needs the undici >= 7.23.0 crash fix, and the package pins `^7.26.0`.)
401+
- Node.js 20.18.1 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
402402
- Deno v1.28.0 or higher.
403403
- Bun 1.0 or later.
404404
- Cloudflare Workers.

src/_shims/index-deno.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ type _fetch = typeof fetch;
1010
export { _fetch as fetch };
1111

1212
// The platform `fetch` already negotiates HTTP/2 at the transport layer, so
13-
// `{ http2: ... }` is a no-op on Deno — reuse the global fetch and ignore any passed
14-
// dispatcher (undici dispatchers are a Node-only concept).
13+
// `{ http2: ... }` is a no-op on Deno — reuse the global fetch and ignore any
14+
// passed pool options (the `node:http2` transport is Node-only).
1515
export const makeHttp2Fetch = () => _fetch;
1616

1717
const _Request = Request;

src/_shims/index.d.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ export const fetch: SelectType<typeof manual.fetch, typeof auto.fetch>;
1717

1818
/**
1919
* Build an HTTP/2-capable `fetch`, used when the client is constructed with
20-
* `{ http2: ... }`. In Node this is the undici adapter (`Agent({ allowH2: true })`);
21-
* the optional `dispatcher` lets the caller pass a configured undici `Dispatcher`
22-
* (the `http2: <Dispatcher>` passthrough), defaulting to the SDK's bounded pool. On
23-
* the web it returns the platform `fetch`, which already negotiates HTTP/2.
20+
* `{ http2: ... }`. On Node this is the native `node:http2` transport; the
21+
* optional `options` tune its connection pool (the `http2: <H2FetchOptions>`
22+
* passthrough), defaulting to the SDK's shared bounded pool. On the web it
23+
* returns the platform `fetch`, which already negotiates HTTP/2.
2424
*/
25-
export function makeHttp2Fetch(dispatcher?: any): typeof fetch;
25+
export function makeHttp2Fetch(options?: any): typeof fetch;
2626

2727
// @ts-ignore
2828
export type Request = SelectType<manual.Request, auto.Request>;

src/_shims/registry.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export interface Shims {
88
fetch: any;
99
/**
1010
* Build an HTTP/2-capable `fetch`, used when the client is constructed with
11-
* `{ http2: ... }`. In Node this is the undici adapter (`Agent({ allowH2: true })`);
12-
* the optional `dispatcher` lets the caller pass a configured undici `Dispatcher`
13-
* (the `http2: <Dispatcher>` passthrough), defaulting to the SDK's bounded pool. On
14-
* the web the platform `fetch` already negotiates HTTP/2, so the argument is ignored.
11+
* `{ http2: ... }`. On Node this is the native `node:http2` transport; the
12+
* optional `options` tune its connection pool (the `http2: <H2FetchOptions>`
13+
* passthrough), defaulting to the SDK's shared bounded pool. On the web the
14+
* platform `fetch` already negotiates HTTP/2, so the argument is ignored.
1515
*/
16-
makeHttp2Fetch: (dispatcher?: any) => any;
16+
makeHttp2Fetch: (options?: any) => any;
1717
Request: any;
1818
Response: any;
1919
Headers: any;

src/_shims/web-runtime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ export function getRuntime({ manuallyImported }: { manuallyImported?: boolean }
3636
kind: 'web',
3737
fetch: _fetch,
3838
// The platform `fetch` already negotiates HTTP/2 at the transport layer, so
39-
// `{ http2: ... }` is a no-op on the web — reuse the global fetch and ignore any
40-
// passed dispatcher (undici dispatchers are a Node-only concept).
39+
// `{ http2: ... }` is a no-op on the web — reuse the global fetch and ignore
40+
// any passed pool options (the `node:http2` transport is Node-only).
4141
makeHttp2Fetch: () => _fetch,
4242
Request: _Request,
4343
Response: _Response,

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ export class Runloop extends Core.APIClient {
361361
* @param {number} [opts.timeout=30 seconds] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
362362
* @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
363363
* @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
364-
* @param {boolean | H2FetchOptions} [opts.http2=true] - Send requests over HTTP/2 (Node only; ignored when `fetch` is provided). Enabled by default; pass `false` to use HTTP/1.1, or H2FetchOptions to tune the pool.
364+
* @param {boolean | H2FetchOptions} [opts.http2=true] - Send requests over HTTP/2. Enabled by default on Node.js; pass `false` to use HTTP/1.1, or H2FetchOptions to tune the pool. Has no effect on browsers/Deno/Bun (their platform `fetch` already uses HTTP/2) or when a custom `fetch` is provided.
365365
* @param {number} [opts.maxRetries=5] - The maximum number of times the client will retry a request.
366366
* @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
367367
* @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.

src/lib/h2-transport/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/**
22
* A high-performance HTTP/2 fetch adapter built on Node's native `node:http2`.
33
*
4-
* Replaces undici for HTTP/2 transport. Manages a pool of persistent H2 sessions
5-
* per origin, multiplexing requests as concurrent streams. Each session handles up
6-
* to the server-advertised MAX_CONCURRENT_STREAMS; the pool auto-scales between
7-
* minConnections and maxConnections as load requires.
4+
* Manages a pool of persistent H2 sessions per origin, multiplexing requests as
5+
* concurrent streams. Each session handles up to the server-advertised
6+
* MAX_CONCURRENT_STREAMS; the pool auto-scales between minConnections and
7+
* maxConnections as load requires.
88
*
99
* Usage:
1010
* const fetch = createH2Fetch({ maxConnections: 20 });

src/lib/http2-transport.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@ import { type Fetch } from '../core';
33
import type { H2FetchOptions } from './h2-transport';
44

55
/**
6-
* Transport-selection logic for the client. Kept out of the generated
7-
* `src/index.ts` so the generated file only holds a one-line call-site hook.
6+
* Transport-selection logic for the client, kept out of the generated
7+
* `src/index.ts` (which holds only a one-line call-site hook).
88
*
9-
* HTTP/2 is the default on Node. The web/Deno shims make {@link makeHttp2Fetch}
10-
* a no-op that returns the platform `fetch`, so this is effectively Node-only.
9+
* This selection matters only on Node.js. There the SDK's default transport is
10+
* `node-fetch`, which speaks HTTP/1.1, so using HTTP/2 means swapping in the
11+
* dedicated `node:http2` transport that {@link makeHttp2Fetch} builds. On
12+
* browsers, Deno, and Bun the platform `fetch` already negotiates HTTP/2, so the
13+
* shim's {@link makeHttp2Fetch} simply returns that platform `fetch` and this
14+
* whole resolution is effectively a no-op.
1115
*/
1216

1317
// A single HTTP/2 transport shared by every client that uses the default pool,

0 commit comments

Comments
 (0)