Initializer
init(stream:count:)
Creates a chunked, streaming HTTP
Response body.init(stream: @escaping @Sendable (borrowing any HTTPBodyWriter & ~Escapable) async throws -> Void, count: Int?) throws
Parameters
streamThe closure that writes the body chunks.
countThe number of bytes that will be written. The
streamMUST produce exactlycountbytes.nilmeans the length is not known in advance, and the response is chunked.
Discussion
The closure receives a HTTPBodyWriter and writes chunks to it with await. Writes are backpressured by the transport, so the closure naturally throttles to the speed of the client. Throwing from the closure fails the response.
Throws
Response.Body.NegativeCountError if count is negative.