Request / Response / Headers
The three objects shared by fetch and http.serve:
Request— an outbound request (or the inbound one, in a handler)Response— what you return from a handler or get fromfetchHeaders— a case-insensitive header collection
Response
Constructor
Properties
Body readers
Readers do not consume — call any reader any number of times, in any order:
clone() corrupts instead of teeing — observed verbatim:
Statics
In an HTTP handler
Response.error() builds a network-error-shaped response (status: 0,
type: "error"). The WebSocket upgrade is automatic and never passes
through your handler — there is no { status: 101 } return (see
WebSocket).
Request
Constructor
Properties
Methods
text(), json(), arrayBuffer(), blob(), formData(), bytes(),
clone() — same contract as Response. Plus:
Headers
Names are case-insensitive; iteration order is insertion order.
Iterating
Headers itself is not iterable — iterate the arrays entries() returns:
Gotchas
bodyUsednever flips — it staysfalsebefore, during, and after every read. Don't branch on it; bodies are simply re-readable.headers.sizeis a function —h.sizeisundefined;h.size()is the number. Same forURLSearchParams.size.clone()corrupts the copy ("OKABCDEFGH"→"OKOKABCDEF") — re-read the original instead of cloning.new Response(body)copies the bytes; mutating the original afterwards does not change the response.Response.redirect(url)without a URL throws — and with one it still sends noLocationheader, so clients never follow it.Requesthas nosignal— there is noAbortControllerin Fairyfly.- In a handler, the third argument (
body) is already a string — you don't call.text()on it.
See also
fetch— usingRequestoutbound- HTTP Server — returning
Response - Blob and FormData —
blob()/formData() - WebSocket — the
101response
