Skip to content

http: add experimental Fetch Server API prototype - #67447

Draft
jasnell wants to merge 11 commits into
nodejs:mainfrom
jasnell:jasnell/fetch-server-api
Draft

jasnell wants to merge 11 commits into
nodejs:mainfrom
jasnell:jasnell/fetch-server-api

Conversation

@jasnell

@jasnell jasnell commented Nov 12, 2026 •

Copy link
Copy Markdown
Member

Add an early prototype of the Fetch Server API proposal
(https://proposal-fetch-server.jasnell.me/), exposed as
http.fetchServer behind the new --experimental-http-serve flag.

The fundamental idea is a HTTP server API that is HTTP version agnostic and supports the full range of newer HTTP features like tunnels, unreliable datagrams, WebTransport (once QUIC/H3 are done), etc.

HTTP/3, QUIC, WebTransport, and HTTP/3 datagrams are not supported and
throw NotSupportedError. WebSocket upgrades are not implemented yet.

This has not yet been performance optimized and it's definitely slower than the current API.

Consider it a proof of concept.

Extremely experimental and very much in flux.

Some notes on the design:

  1. This is INTENTIONALLY not Node.js specific. That means no Node.js specific APIs surfaced through the API surface. The goal is for this to be implemented across multiple runtimes.
  2. This is also INTENTIONALLY not dependent on WHATWG fetch APIs. Those are too slow and we need to have options for optimizing that are not currently afforded by the WHATWG specs/process.

@nodejs/quic @nodejs/http @nodejs/http2 @mcollina

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config
  • @nodejs/http
  • @nodejs/net
  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. config Issues and PRs related to Node.js configuration and feature settings. http Issues and PRs related to the http subsystem. needs-ci PRs that need a full CI run. labels Nov 12, 2026
@fry69

fry69 commented Nov 13, 2026

Copy link
Copy Markdown

Looks like https://fetch-server.proposal.wintertc.org/ is not yet online?

I found this link instead, if that helps -> https://proposal-fetch-server.jasnell.me/

Also this repo -> https://github.com/jasnell/proposal-fetch-server

@bnb

bnb commented Nov 13, 2026

Copy link
Copy Markdown
Member

this is sick, great work @jasnell

@Ethan-Arrowood

Copy link
Copy Markdown
Contributor

Nice 😎 looking forward to digging into this.

Comment thread lib/internal/http/serve/h1.js Resolved
Comment thread lib/internal/http/serve/tunnel.js Resolved
type: type[0],
data: TypedArrayPrototypeSubarray(this.#buffer, length[1], end),
});
this.#buffer = TypedArrayPrototypeSubarray(this.#buffer, end);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the next thing. The parser needs to check if the capsule is unusually big for the capsule type, to prevent misuse. (again my WT code does this, so may be should at some point do sth combined).
For example for WT there are big capsules types (big WT data types including fins), these I deliver in a streaming way to not consume unnecessary memory. Of course, this adds complexity and I hope I found most bugs in my code. On the flip side my code is wt specific and I do not know of a general interface for capsules, yet. I have hardcoded all capsule type as I hoped the js jit compiler would optimize it (though I have only C++ experience in optimization).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parser that's here is just a stand-in for something actually robust/real.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, got it. But one point is about the interface, I think for big capsule passing them by complete Uint8Array's is a design problem.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I defer to you on the right design of that particular piece. As I said, what is here is really just a placeholder at the moment

@jasnell

jasnell commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

@nodejs/undici @nodejs/quic @nodejs/http I'm considerig whether it would be better to develop this API under core here or within nodejs/undici ... looking for opinions.

@marco-ippolito

Copy link
Copy Markdown
Member

I think undici would be the right place

@martenrichter

Copy link
Copy Markdown
Contributor

And where should a Webtransport http/2 capsule parser go? I am just asking as I am just in the course of adding primordials and validation function to the code I want to contribute to node.js. (And these do not seem to exists in undici)

@mb21

mb21 commented Nov 28, 2026

Copy link
Copy Markdown

As long as nodejs/undici#5989 is unresolved, I'm not sure undici would be the best place, considering the discussion in e.g. nodejs/undici#5415

@jasnell

jasnell commented Nov 29, 2026

Copy link
Copy Markdown
Member Author

I think the capsule parser makes sense here.

@jasnell jasnell added large-pr PRs subject to the large-PR policy. experimental Issues and PRs related to experimental features. labels Nov 29, 2026
@jasnell
jasnell force-pushed the jasnell/fetch-server-api branch from 7f2af4b to a86d1b5 Compare November 29, 2026 13:51
Add an early prototype of the WinterTC Fetch Server API proposal
(https://fetch-server.proposal.wintertc.org/), exposed as
`http.fetchServer` behind the new `--experimental-http-serve` flag.

This includes:

* `ServerResponse`, `ServerHeaders`, and `ServerRequest` with
  iterable-stream bodies, trailers, and cloning.
* The `ServerContext` and `ConnectContext` protocols, the exchange
  state model, informational responses, 100-continue handling,
  `deny()`, `waitUntil()`, and `completed`.
* The handler model, including the error() handler and fallbacks.
* `serve()`, `Server`, and `Listener`, built on the existing
  `node:http` and `node:http2` implementations, with HTTP/1.1, h2c
  (prior knowledge), and TLS with ALPN negotiation of h2.

HTTP/3, QUIC, WebTransport, and HTTP/3 datagrams are not supported and
throw NotSupportedError. WebSocket upgrades are not implemented yet.

Assisted-by: Claude Opus 5.5
Signed-off-by: James M Snell <jasnell@gmail.com>
Add tests for CONNECT, extended CONNECT, HTTP/1.1 upgrade
normalization, fall-through, and capsules over HTTP/2, and fix the
issues they found:

* Defer the RST_STREAM(NO_ERROR) that refuses an unread request body
  until the complete response has been sent, and only send it if the
  client has not already ended its side.
* Send `Content-Length: 0` for HTTP/1.1 responses without a body.

Assisted-by: Claude Opus 5.5
Signed-off-by: James M Snell <jasnell@gmail.com>
Implement `upgradeWebSocket()` and `upgradeWebSocketStream()` for
HTTP/1.1 upgrades and HTTP/2 extended CONNECT (RFC 8441), with:

* RFC 6455 framing: masking, fragmentation, ping/pong, the closing
  handshake, UTF-8 validation, and failing the connection on protocol
  violations.
* A server-side `WebSocket` with the WHATWG event API, whose close()
  accepts the close codes that a server can send.
* `ServerWebSocketStream`, whose readable and writable streams apply
  backpressure in both directions.
* Subprotocol selection by server preference, opt-in permessage-deflate
  (RFC 7692), `pingInterval`, and the `closeHandshake` and `tunnelIdle`
  timeouts.
* Close code 1001 on graceful server shutdown.

Assisted-by: Claude Opus 5.5
Signed-off-by: James M Snell <jasnell@gmail.com>
Add a self-contained "Fetch Server API" section to the `node:http`
documentation, covering `http.fetchServer.serve()`, the handler model,
`Server`, `Listener`, `ServerResponse`, the context and request
protocols, tunnels, WebSocket upgrades, protocol errors, and the
limitations of the prototype.

Assisted-by: Claude Opus 5.5
Signed-off-by: James M Snell <jasnell@gmail.com>
Add benchmarks for the fetch() handler of the experimental
`http.fetchServer` API over HTTP/1.1 and HTTP/2, each with and without
TLS. Let the HTTP/2 test double connect to servers with self-signed
certificates, as the HTTPS test double already does.

Assisted-by: Claude Opus 5.5
Signed-off-by: James M Snell <jasnell@gmail.com>
Profiling showed that a response with a small body made two writes and
several promise races, and paid for request state that was not used.

* Send a body that is held as bytes, such as one from a string or a
  Uint8Array, with its Content-Length in a single write, instead of
  with chunked encoding in separate writes.
* Race exchange operations against an abort with a single promise that
  `abort()` rejects, instead of `SafePromiseRace()`. This also stops
  every race from adding a reaction to a promise that lives as long as
  the exchange.
* Hold the state of a context in a private field instead of a
  non-enumerable property.
* Build the HTTP/1.1 request header list lazily, without copying the
  hop-by-hop field set, and do not create the ServerRequest to check
  for HEAD.

Assisted-by: Claude Opus 5.5
@jasnell
jasnell force-pushed the jasnell/fetch-server-api branch from a86d1b5 to 1ff6299 Compare November 29, 2026 15:51
Signed-off-by: James M Snell <jasnell@gmail.com>
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Claude
... to internal/http/serve

Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell
jasnell force-pushed the jasnell/fetch-server-api branch from 1ff6299 to cc66977 Compare November 29, 2026 16:03
Signed-off-by: James M Snell <jasnell@gmail.com>
Signed-off-by: James M Snell <jasnell@gmail.com>
Assisted-by: Claude
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. config Issues and PRs related to Node.js configuration and feature settings. experimental Issues and PRs related to experimental features. http Issues and PRs related to the http subsystem. large-pr PRs subject to the large-PR policy. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants