Browse documentation

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 POST alongside GET and HEAD. fetch() accepts "GET", "HEAD", and "POST" (case-insensitive) and rejects all other methods (such as PUT, PATCH, DELETE, OPTIONS) with TypeError.
  • Accept options.body on POST only. Passing a non-null, non-undefined body with GET or HEAD rejects with TypeError. POST bodies convert through the same buffered extractBody path as new Response(body): Blob, ArrayBuffer, typed arrays and DataView, URLSearchParams, and strings (rejecting Symbol with TypeError), copying bytes synchronously before dispatch and setting the inferred Content-Type when 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. HTTPPost always sends Content-Length (including 0 for an empty POST) and ignores caller Content-Length and Transfer-Encoding headers. On 301, 302, and 303 redirects, a POST becomes a GET and drops its body and body-specific headers (Content-Encoding, Content-Language, Content-Location, Content-Type). On 307 and 308, POST, its body, and its content headers are preserved (cross-origin credential stripping still applies), and the redirected POST opens 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.Body carries the request body bytes to embedder transports and FetchOverNetwork. 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 forward POST requests and bodies.

Consequences

  • Scripts granted --allow-net for a host can now send POST requests 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) and FormData remain out of scope; request bodies are buffered whole.