workerd / http-server
AGENTS.md8.8k starsChanged 9 months agoApache-2.0View on GitHub
An informal specification of how a node:http Server drives the web streams underneath it — the Request body it pumps into the IncomingMessage, and the ReadableStream the ServerResponse builds as the body of the Response it hands back to fetch() — derived from and kept in lockstep with the test suite in this directory. The tests are the normative artifact; this document maps behaviors to the tests that assert them. Every test runs against the C++ streams implementation (http-server-cpp.wd-test) and…
Trending
Quiet since August.thin dataabout the whole repository
Who's talking about cloudflare/workerd
- A Hacker News story“OS Workerd, Cloudflare's JavaScript/WASM Runtime”Hacker News · Sep 27, 2022 · 27 points
- withastro/astro“Cloudflare adapter returning [object Object]”GitHub · Oct 10, 2025 · 18 reactions
- supabase/supabase-js“The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers”GitHub · Mar 28, 2024 · 16 reactions
- nodejs/node“src: improve buffer.transcode performance”GitHub · Aug 1, 2024 · 13 reactions
- NixOS/nixpkgs“Package request: workerd”GitHub · Nov 12, 2024 · 12 reactions
The biggest 5 of 12 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 12
Talked about on GitHub, Bluesky and Hacker News (12 times).
On GitHub · 6
- Oct 10, 2025Cloudflare adapter returning [object Object] — withastro/astro18 reactions · 15 comments
- Mar 28, 2024The 'cache' field on 'RequestInitializerDict' is not implemented - Cloudflare Workers — supabase/supabase-js16 reactions · 24 comments
- Aug 1, 2024src: improve buffer.transcode performance — nodejs/node13 reactions · 26 comments
- Nov 12, 2024Package request: workerd — NixOS/nixpkgs12 reactions · 8 comments
- Feb 19, 2024Add Curve25519 — w3c/webcrypto9 reactions · 16 comments
1 more on GitHub
- Nov 3, 2025Optimize TextEncoder::encode — nodejs/performance7 reactions · 33 comments
On Bluesky · 4
- Mar 24, 2026workerd : le runtime JavaScript/Wasm open source de Cloudflare Workers — @news.humancoders.com4 likes and reposts
- Aug 22, 2026Current status: trying to build github.com/cloudflare/w... on various sandbox providers — @jeremymorrell.dev1 likes and repost
- Mar 24, 2026workerd : le runtime JavaScript/Wasm qui propulse Cloudflare Workers est maintenant open source. Basé sur les standards web, il permet… — @humancoders.com1 likes and repost
- Nov 5, 2024Technically workers are open source github.com/cloudflare/w... — @userops.bsky.social1 likes and repost
On Hacker News · 2
- Sep 27, 2022OS Workerd, Cloudflare's JavaScript/WASM Runtime27 points · 2 comments
- Oct 5, 2023Cloudflare workers is adopting Ada URL parser2 points
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository61 other files it gives its agents.
- AGENTS.mdAGENTS.md
- build/AGENTS.mdAGENTS.md
- src/cloudflare/AGENTS.mdAGENTS.md
- src/node/AGENTS.mdAGENTS.md
- src/per_isolate/AGENTS.mdAGENTS.md
- src/per_isolate/crypto/AGENTS.mdAGENTS.md
- src/per_isolate/webfs/AGENTS.mdAGENTS.md
- src/per_isolate/webstreams/AGENTS.mdAGENTS.md
- src/pyodide/AGENTS.mdAGENTS.md
- src/rust/AGENTS.mdAGENTS.md
- src/rust/cxx/AGENTS.mdAGENTS.md
- src/tests/node/AGENTS.mdAGENTS.md
- src/tests/node/http-client/AGENTS.mdAGENTS.md
- src/tests/node/net/AGENTS.mdAGENTS.md
- src/tests/node/stream/AGENTS.mdAGENTS.md
- src/tests/streams/AGENTS.mdAGENTS.md
- src/tests/streams/cache/AGENTS.mdAGENTS.md
- src/tests/streams/compression/AGENTS.mdAGENTS.md
- src/tests/streams/digest/AGENTS.mdAGENTS.md
- src/tests/streams/encoding/AGENTS.mdAGENTS.md
- src/tests/streams/formdata/AGENTS.mdAGENTS.md
- src/tests/streams/htmlrewriter/AGENTS.mdAGENTS.md
- src/tests/streams/identity/AGENTS.mdAGENTS.md
- src/tests/streams/inspect/AGENTS.mdAGENTS.md
- src/tests/streams/iocontext/AGENTS.mdAGENTS.md
- src/tests/streams/piping/AGENTS.mdAGENTS.md
- src/tests/streams/r2-patterns/AGENTS.mdAGENTS.md
- src/tests/streams/readable/AGENTS.mdAGENTS.md
- src/tests/streams/readable-byte/AGENTS.mdAGENTS.md
- src/tests/streams/scaling/AGENTS.mdAGENTS.md
- src/tests/streams/sockets/AGENTS.mdAGENTS.md
- src/tests/streams/strategies/AGENTS.mdAGENTS.md
- src/tests/streams/transform/AGENTS.mdAGENTS.md
- src/tests/streams/writable/AGENTS.mdAGENTS.md
- src/workerd/api/AGENTS.mdAGENTS.md
- src/workerd/api/crypto/AGENTS.mdAGENTS.md
- src/workerd/api/node/AGENTS.mdAGENTS.md
- src/workerd/api/streams/AGENTS.mdAGENTS.md
- src/workerd/io/AGENTS.mdAGENTS.md
- src/workerd/jsg/AGENTS.mdAGENTS.md
- src/workerd/server/AGENTS.mdAGENTS.md
- src/workerd/util/AGENTS.mdAGENTS.md
- types/AGENTS.mdAGENTS.md
- bazel-test-hygieneSkill
- commit-categoriesSkill
- dad-jokesSkill
- find-and-run-testsSkill
- identify-reviewerSkill
- investigation-notesSkill
- kj-styleSkill
- markdown-draftsSkill
- parent-project-skillsSkill
- pr-review-guideSkill
- receiving-code-reviewSkill
- rust-reviewSkill
- ts-styleSkill
- update-v8Skill
- wd-test-formatSkill
- workerd-api-reviewSkill
- workerd-safety-reviewSkill
- The first 60 shown.
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 26
No sidecar. The worker is bound to itself as SERVICE.
- Very specific: line 83
Every chunk type is delivered (string, Buffer, Uint8Array, explicit encoding), empty writes contribute nothing, many small and large writes …
- Very specific: line 127
Before that, destroy(err) emits 'error' then 'close'.
- Distinctive: line 172
Every assertion holds unchanged under both implementations.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
node:http server × web streams
An informal specification of how a node:http Server drives the web
streams underneath it — the Request body it pumps into the
IncomingMessage, and the ReadableStream the ServerResponse builds as
the body of the Response it hands back to fetch() — derived from and
kept in lockstep with the test suite in this directory. The tests are
the normative artifact; this document maps behaviors to the tests that
assert them. Every test runs against the C++ streams implementation
(http-server-cpp.wd-test) and the TypeScript one
(http-server-ts.wd-test). The general server surface (headers, options,
ports, listen/close lifecycle, cloudflare:node helpers) is owned by
src/workerd/api/node/tests/http-server-nodejs-test.js; this suite owns
the STREAMS interaction only.
The implementation under test is src/node/internal/internal_http_server.ts
(Server#onRequest/#toReqRes and its [captureRejectionSymbol], and
ServerResponse: the Response promise, #toFetchResponse,
destroy/#emitClose),
internal_http_incoming.ts (IncomingMessage#tryRead, _read,
_destroy) and the OutgoingMessage write path in
internal_http_outgoing.ts.
Infrastructure
No sidecar. The worker is bound to itself as SERVICE; its default
handler (main.js) routes every incoming Request to the current test's
server through handleAsNodeRequest. harness.js offers the two ways a
Request reaches a server:
env.SERVICE.fetch(...): through the service binding. The runtime pumps bodies across it (the production shape); a cancellation on one side reaches the other only once the exchange completes.dispatch(new Request(...)): an in-isolate Request handed to the server directly, so its body stream IS the test's stream and cancellation is observable at once. Tests that need it callremember(env, ctrl)first.
Tests run sequentially, one server (withServer) at a time.
Core semantics
The request body
- The
Requestbody is pumped into theIncomingMessageby one default reader, acquired on the first_read()and held for the message's lifetime; the pump reads untilpush()reports backpressure or EOF and_read()restarts it with the same reader. A request without a body (GET) ends at once withcompleteset. - Chunks arrive as Buffers (strings under
setEncoding), whole and in order; a body the client streams arrives incrementally and is chunked (no Content-Length), aFixedLengthStreambody announces its length. A 'data' listener attached inside the handler still sees the body. pause()holds delivery,resume()continues it without loss, also for a body larger than the high-water mark.pipe()to one or several node destinations andpipeline(req, TransformStream, res)work;pipe()is the Readable's: a destination's backpressure pauses the body and 'drain' resumes it, the destination hears 'pipe'/'unpipe', a destination that errors is unpiped (no further write reaches it),unpipe()stops delivery and pauses a source left without destinations, and a source error is not forwarded to the destination (that ispipeline()'s job).destroy(): 'aborted' when the body was not complete, 'error' only when the message has an 'error' listener (an unlisteneddestroy(err)is swallowed), 'close' always; the body stream is cancelled with the destroy reason (undefinedfor a baredestroy()), through the held reader when the pump had acquired one, unless the body was already read to completion. A read pending acrossdestroy()is dropped, however the stream settles it — also on the runtime's stream across the binding (ledger #1).- The body stream failing under the message — erroring mid-upload, or while
the handler has the message paused with a read pending underneath, or
yielding a chunk the message cannot take (a view over a detached
ArrayBuffer: the conversion's
TypeError) — aborts it: 'aborted', the error, 'close' withcompletefalse; the response can still be sent.pause()thenresume()inside every 'data' loses nothing.
The response body
- Headers go out at the first
write()/end()(writeHead()only formats them; the first write sends them implicitly if needed), which resolves theResponse— while the handler is still writing. The body is anew ReadableStream({ type: 'bytes' }): writes before the headers are buffered and flushed into it at that point, later writes are enqueued as they come, so a client reads chunks beforeend(). - Every chunk type is delivered (string, Buffer,
Uint8Array, explicit encoding), empty writes contribute nothing, many small and large writes arrive whole. A declared Content-Length caps the body (extra bytes dropped, fewer sent as they are) atparseInt's reading of it — a non-numeric value leaves the body uncapped, zero or a negative value drops every chunk, a fraction or padded number caps at its integer part. (The header value itself is not validated; whether a malformed one keeps reaching the client is deliberately unpinned.) 204 and 304, and the reply to a HEAD (marked bodiless before the handler runs), have a null body and drop their writes — accepted, callback called — or, under the server'srejectNonStandardBodyWritesoption, refuse them withERR_HTTP_BODY_NOT_ALLOWED. A webReadableStreamcan bepipeline()d into the response. - A written buffer stays the caller's: the response copies each chunk as
it flushes it into the body stream (whose enqueue would otherwise
transfer, i.e. detach, the buffer), so a buffer is reusable once the
write's callback has fired and a mutation after that is not sent (one in
the same tick as the write is, as with Node's corked socket). Views over
a
SharedArrayBufferor aWebAssembly.Memoryare written like any other; zero-length views, detached ones included, contribute nothing. write()reports backpressure against the response's own buffer before the headers, with 'drain' following; once the headers are out every write is accepted (the body stream queues whatever the handler writes; the client's consumption does not feed back), so no 'drain' is owed.cork()/uncork()batch writes (writableLengthcounts the header bytes too). The server'shighWaterMarkoption is the response'swritableHighWaterMark.
The response lifecycle
- 'finish' fires once the body has been handed off, and closes the stream;
'close' follows it (a microtask later), once, and marks the response
destroyed (
stream.finished(res)reports that 'close', as in Node): awrite()afterend()fails through its callback withERR_STREAM_WRITE_AFTER_END(a secondend()is inert) and, once the response is closed, never as an 'error' event. - Once
end()has been called,destroy()— with or without an error, from inside 'finish' or right afterend()— aborts nothing: the body was handed off byend(), so the whole of it reaches the client, no 'error' fires and 'close' still follows 'finish', once. The response is markeddestroyed(anderroredwith the reason) at once, as Node'sOutgoingMessage.destroy(error)marks it, so a write that follows fails through its callback alone. Nothing escapes the isolate. (destroy()takes the error alone, as Node's does; there is no callback.) - Before that,
destroy(err)emits 'error' then 'close'. Before the headers, the Response promise rejects witherr— or, for a baredestroy(), withERR_STREAM_PREMATURE_CLOSE(aTypeError'Premature close') — so the fetch fails instead of waiting. After the headers, the body errors witherror thatERR_STREAM_PREMATURE_CLOSE; nothing reaches the body's controller once it has closed or errored — a chunk the message buffer still holds when the response is destroyed is dropped, as a destroyed socket's pending writes are in Node. - A request listener that throws synchronously destroys the response with
the error ('error', 'close') and the fetch rejects with it — also after
writeHead()and awrite(), whose Response is then discarded. An async listener whose promise rejects ends the same way (the server captures its listeners' rejections; Node's process would die of the unhandled rejection, a Worker cannot): before any header the fetch rejects with the error, after a partial body the Response's body errors with it. - Another event's listener rejecting (a 'listening' listener, say) is
reported as
EventEmitter's own capture fallback reports one: as the server's 'error' event — heard by an 'error' listener, thrown uncaught without one. An 'error' listener's own rejection is re-raised uncaught, once, never emitted as another 'error'. - The body stream's
cancel(reason)— a client abandoning the response — destroys the response withreason: 'error', 'close', later writes fail withERR_STREAM_DESTROYED.
Compatibility flags
| Flag (enable date) | Selects | Unflagged behavior tested by |
streams_enable_constructors (2022-11-30) | the ServerResponse can build its body stream (and the tests their web streams) | legacyFirstBodyWriteHitsConstructorGate, legacyUncaughtGateErrorFailsFetch |
transformstream_enable_standard_constructor (2022-11-30) | new TransformStream({ transform }) in the pipeline tests (gate pinned in src/tests/node/stream) | — |
enable_nodejs_http_modules, enable_nodejs_http_server_modules (2025-08-15 / 2025-09-01) | the server classes; pinned in every cell | — |
unhandled_rejection_after_microtask_checkpoint (2026-03-03) | accurate unhandledrejection reporting, which collectUncaught relies on: the C++ implementation settles a read pending at cancel() through a rejected promise adopted a tick later, which the earlier tracker reported before its handler ran (ledger #1) | legacyPendingReadCancelMisfiresAsUnhandledRejection |
nodejs_compat_v2 is deliberately absent from every cell: the http layer
must not depend on its globals. http-server-ts.wd-test omits the three
flags the TypeScript implementation does not consult —
streams_enable_constructors, transformstream_enable_standard_constructor
and unhandled_rejection_after_microtask_checkpoint — and its variants
prove the implementation is indifferent to them (its cancel resolves a
pending read done, so no rejected promise exists for the earlier tracker
to misreport).
Divergence ledger (C++ vs TypeScript)
Every assertion holds unchanged under both implementations; the one divergence underneath is swallowed by the message and is observable only through the isolate's rejection bookkeeping.
| # | Area | C++ | TypeScript | Pinned in |
| 1 | The body pump's read pending when destroy() cancels the runtime's body stream (across the binding) | the read rejects with the cancel reason ("Stream was cancelled." for a bare destroy()); #tryRead swallows it (the message is already destroyed). Without unhandled_rejection_after_microtask_checkpoint the tracker reports the rejected promise before that handler runs: a spurious unhandledrejection | the read resolves done (spec); nothing to report at any compat date | destroyWithPendingReadAcrossBinding (identical events, nothing escapes, under both — the cpp cell pins the flag), legacyPendingReadCancelMisfiresAsUnhandledRejection (the misfire, unflagged C++); the pure-streams behavior is src/tests/streams/identity ledger #20 |
(A second divergence would surface if the response fed its controller after
closing it: with a chunk still queued, the TypeScript implementation honors
a late controller.error() per spec while the C++ one ignores it. The
response never does so — see "The response lifecycle" — and the
pure-streams behavior belongs to src/tests/streams/readable.)
Assertion catalogue
| Module | Asserts |
request-body.js | GET ends at once; Buffer/string chunks and complete; late 'data' listener; 256 KiB in several events; streaming body incremental + chunked headers; FixedLengthStream Content-Length; pause/resume (small chunks, and a body above the high-water mark); pipe echo; several pipe destinations; pipeline through a TransformStream |
request-destroy.js | destroy(err) with listener; bare destroy() closes quietly; unlistened destroy(err) swallowed; mid-body destroy cancels the body stream with the reason and stops 'data'; bare destroy cancels with undefined; destroy with the pump's read pending on the runtime's stream across the binding (aborted, closed incomplete, response sent, nothing escapes — ledger #1); no cancel after completion |
response-body.js | implicit headers and chunk types; streaming before end(); large and many writes; Content-Length capping; 204/304; HEAD (_hasBody, dropped writes, null body); rejectNonStandardBodyWrites; cork/uncork; backpressure signaling and 'drain' parity; acceptance after headers with highWaterMark; web source pipelined in; 'finish' then 'close' with closed; finished(res) after 'close'; write after end via callback only; Content-Length lies cap the body at parseInt's reading (abc uncapped, 0 and negative empty, fraction and padded at the integer part; the header echo deliberately unasserted) |
piping.js | 1 MiB into a 16 KiB slow sink: bounded buffer, pauses/resumes, all bytes; unpipe() after the first chunk ('pipe'/'unpipe' on the destination, delivery stops, source paused, rest to a 'data' listener, destination not ended); erroring destination unpiped ('unpipe' before its 'error', one write only, source paused); source error not forwarded (destination stays piped, open, unerrored) |
request-body-failures.js | body stream erroring mid-upload and while paused (aborted, error, close incomplete, response still sent); a detached-view chunk (TypeError) |
reentrancy.js | destroy() and destroy(err) inside 'finish' (body whole, 'close' once, no 'error', nothing escapes); pause/resume inside every 'data' |
then-pollution.js | transparent patched then: request and response bodies intact |
data-volumes.js | an 8 MiB request body across the binding (whole, in order, several chunks); 20,000 one-byte response writes; alternating string/Buffer/Uint8Array/empty writes; a body with UTF-8 sequences split byte by byte, reassembled by setEncoding('utf8') |
buffer-lifecycle.js | fill/write/refill after the callback (intact, not detached, both payloads received); chunk given to end() and its parent allocation intact; mutation after the callback not sent; SAB and WebAssembly.Memory views written, 'finish' only; Content-Length-trimmed writes leave their buffers intact; empty and detached views accepted and skipped |
response-lifecycle.js | destroy(err) before headers rejects the fetch with it; bare destroy before headers → 'Premature close'; destroy(err) after headers errors the body, 'error' then 'close'; bare destroy after headers → premature close, 'close' only; destroy(err) after end() aborts nothing (chunk in end(), bare end() after a write, nothing written): marked destroyed and errored at once, a later write fails through its callback, body whole, 'finish' then 'close', no 'error', nothing escapes; client cancel → destroyed with the reason, ERR_STREAM_DESTROYED on later writes; a listener throwing before headers / after a partial body → fetch rejects with it, nothing else escapes; an async listener rejecting before headers / after a partial body → destroyed with the error, fetch or body failing with it |
listener-rejections.js | an async 'listening' listener rejecting → the server's 'error' event (heard by a listener; thrown uncaught without one); an async 'error' listener's own rejection → uncaught once, not re-emitted |
harness.js, which-impl.js | shared machinery (collectUncaught gathers what escapes the isolate during a test) |
Legacy (unflagged) behaviors
Guarded by http-server-cpp-legacy.wd-test (C++ only):
| Behavior | Asserted by |
writeHead() succeeds; the first body write throws the constructor-gate Error synchronously; a handler that catches it and ends anyway never yields a Response — the fetch fails with 'Premature close' | legacyFirstBodyWriteHitsConstructorGate |
The gate Error left uncaught fails the fetch with that Error | legacyUncaughtGateErrorFailsFetch |
| 204, 304 and the reply to a HEAD construct no stream: status and headers delivered, body null, writes dropped | legacyBodilessResponsesWork |
| The request body (a runtime stream) is pumped as usual | legacyRequestBodyIsPumped |
Without unhandled_rejection_after_microtask_checkpoint, req.destroy() with the pump's read pending on the runtime's stream surfaces a spurious unhandledrejection ('Stream was cancelled.') — the message still aborts and the response is sent (ledger #1) | legacyPendingReadCancelMisfiresAsUnhandledRejection |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

