0251 - fetch supports POST requests with bodies
Date: 2026-12-03
Area: runtime, embedding
Related: ADR 0031, ADR 0146, ADR 0156, ADR 0170, ADR 0237
Context
fetch() and HTTPClient accepted only GET and HEAD. Scripts calling
JSON-RPC, GraphQL, webhook, or form endpoints could not send POST requests
or request bodies, even though Response already extracted BodyInit values,
TGocciaFetchTransportRequest already carried a Body: TBytes field, and
Goccia.Fetch already charged pending request storage against the engine's
memory limit.
Decision
- Allow
POSTalongsideGETandHEAD.fetch()accepts"GET","HEAD", and"POST"(case-insensitive) and rejects all other methods (such asPUT,PATCH,DELETE,OPTIONS) withTypeError. - Accept
options.bodyonPOSTonly. Passing a non-null, non-undefinedbodywithGETorHEADrejects withTypeError.POSTbodies convert through the same bufferedextractBodypath asnew Response(body):Blob,ArrayBuffer, typed arrays andDataView,URLSearchParams, and strings (rejectingSymbolwithTypeError), copying bytes synchronously before dispatch and setting the inferredContent-Typewhen the caller did not provide one. Pending request body bytes are charged against the engine's memory limit (--max-memory). - Fixed-length wire framing and WHATWG redirect semantics.
HTTPPostalways sendsContent-Length(including0for an emptyPOST) and ignores callerContent-LengthandTransfer-Encodingheaders. On301,302, and303redirects, aPOSTbecomes aGETand drops its body and body-specific headers (Content-Encoding,Content-Language,Content-Location,Content-Type). On307and308,POST, its body, and its content headers are preserved (cross-origin credential stripping still applies), and the redirectedPOSTopens a fresh connection rather than reusing keep-alive so a closed socket never triggers a silent retry of a non-idempotent request. - Transport and WebAssembly fetch device parity.
TGocciaFetchTransportRequest.Bodycarries the request body bytes to embedder transports andFetchOverNetwork. The WebAssembly fetch device (Goccia.FetchDevice.Protocol) keeps its single-JSON-object format when the body is empty and appends"bodyLength", a line feed, and the raw body bytes when non-empty; both the Node and browser fetch device hosts forwardPOSTrequests and bodies.
Consequences
- Scripts granted
--allow-netfor a host can now sendPOSTrequests and bodies to that host under the existing capability, redirect, timeout, and memory controls. - Other write methods (
PUT,PATCH,DELETE,OPTIONS) remain unsupported until explicitly decided. - Streaming request bodies (
ReadableStream) andFormDataremain out of scope; request bodies are buffered whole.