TransferEncoding

provides encoding and decoding for HTTP transfer codings.

Use Request.chunked?/Response.chunked? to detect a chunked body, then dechunk to decode it, or chunk to encode one.

chunk

defn

(Fn [(Ref String a)] String)

                        (chunk body)
                    

chunk-encodes body as a single chunk followed by the terminating zero-size chunk (RFC 7230 §4.1). The result decodes back to body via dechunk; an empty body yields just the terminator.

chunk-with-size

defn

(Fn [(Ref String a), Int] String)

                        (chunk-with-size body size)
                    

chunk-encodes body into chunks of at most size bytes per RFC 7230 §4.1 — each a hex size line, the data, and a CRLF — closed by the terminating zero-size chunk. size is clamped to at least 1. The result decodes back to body via dechunk.

dechunk

defn

(Fn [(Ref String a)] (Result String String))

                        (dechunk body)
                    

decodes a chunked transfer-encoded body per RFC 7230 §4.1.

Each chunk is a hexadecimal size line — any chunk extension after a ; is ignored — followed by that many bytes of data and a CRLF, repeating until a zero-size chunk. Optional trailer headers after the final chunk are ignored. Returns the decoded body, or an (Error String) on malformed framing such as a bad hex size or a truncated chunk.