Chunked Transfer Coding (std/chunked)
from "std/chunked" import { ChunkScan, decodeChunked }HTTP/1.1 chunked transfer coding (RFC 9112 §7.1): framing and decoding, with no IO. std/fetch reads chunked responses with it and std/http reads chunked request bodies. It is a separate module so a plain HTTP server can decode chunked bodies without linking OpenSSL, which std/fetch pulls in.
Most programs never call it: fetch and std/http handlers see the decoded body. Reach for it only when you read HTTP framing off a socket yourself. ChunkScan checks the framing incrementally as bytes arrive; decodeChunked extracts the data once the body is complete.
API reference
ChunkScan
pub struct ChunkScanAn incremental walk over a chunked body that is still arriving. Each step resumes after the last complete chunk instead of rescanning from the start, so reading a body in many segments stays linear.
ChunkScan.declared
fn ChunkScan.declared(self: &ChunkScan): i64Data bytes the body declares so far: every complete chunk plus the size the chunk still arriving announced. A server compares this with its body limit before the bytes arrive, so a chunk declaring a gigabyte is refused at its size line.
ChunkScan.new
fn ChunkScan.new(start: i64): ChunkScanA scan of a chunked body that starts at offset start (just past the headers).
ChunkScan.step
fn ChunkScan.step(self: &mut ChunkScan, raw: &string): i64Index just past the body (last chunk and trailers included), chunkIncomplete while more bytes are needed, or chunkMalformed.
Functions
decodeChunked
pub fn decodeChunked(raw: &string, from: i64): stringThe data of the chunked body in raw from offset from, chunk extensions and trailers dropped. Lenient: it decodes as far as the framing goes and stops at the last chunk or the end of input, so a caller that must refuse bad framing checks it with ChunkScan first.