DoxigAlpha

endChunkedUnflushed

Writes the end-of-stream message and any optional trailers.

Does not flush.

Asserts that the BodyWriter is using transfer-encoding: chunked.

Respects the value of isEliding to omit all data after the headers.

See also:

  • endChunked
  • endUnflushed
  • end

Function parameters

Parameters

#
w:*BodyWriter

Type definitions in this namespace

Types

#
Method
https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods
Status
https://developer.mozilla.org/en-US/docs/Web/HTTP/Status
TransferEncoding
compression is intentionally omitted here since it is handled in `ContentEncoding`.
BodyWriter
Request or response body.

Source

Implementation

#
pub fn endChunkedUnflushed(w: *BodyWriter, options: EndChunkedOptions) Error!void {
    if (w.isEliding()) {
        w.state = .end;
        return;
    }
    const bw = w.http_protocol_output;
    switch (w.state.chunk_len) {
        0 => {},
        1 => unreachable, // Wrote more data than specified in chunk header.
        2 => try bw.writeAll("\r\n"),
        else => unreachable, // An earlier write call indicated more data would follow.
    }
    try bw.writeAll("0\r\n");
    for (options.trailers) |trailer| {
        try bw.writeAll(trailer.name);
        try bw.writeAll(": ");
        try bw.writeAll(trailer.value);
        try bw.writeAll("\r\n");
    }
    try bw.writeAll("\r\n");
    w.state = .end;
}