Repository navigation
Conversation
|
Review requested:
|
|
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 |
|
this is sick, great work @jasnell |
|
Nice 😎 looking forward to digging into this. |
| type: type[0], | ||
| data: TypedArrayPrototypeSubarray(this.#buffer, length[1], end), | ||
| }); | ||
| this.#buffer = TypedArrayPrototypeSubarray(this.#buffer, end); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
The parser that's here is just a stand-in for something actually robust/real.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
|
@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. |
|
I think undici would be the right place |
|
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) |
|
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 |
|
I think the capsule parser makes sense here. |
7f2af4b to
a86d1b5
Compare
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
a86d1b5 to
1ff6299
Compare
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>
1ff6299 to
cc66977
Compare
Signed-off-by: James M Snell <jasnell@gmail.com>
Signed-off-by: James M Snell <jasnell@gmail.com> Assisted-by: Claude
Add an early prototype of the Fetch Server API proposal
(https://proposal-fetch-server.jasnell.me/), exposed as
http.fetchServerbehind the new--experimental-http-serveflag.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:
@nodejs/quic @nodejs/http @nodejs/http2 @mcollina