Skip to content

You're viewing documentation for a pre-release version. View the latest stable version

Instance Method

withReader(_:)

Lends a RequestBodyReader for the duration of body, so the handler can drive the read loop itself (read a single chunk, interleave reads with other work). The reader is non-escapable: using it after the request moved on is a compile-time error.
consuming func withReader<R>(_ body: (borrowing any RequestBodyReader & ~Escapable) async throws -> R) async throws -> R

Discussion

Important

Reading directly bypasses maxBodySize, which only collect(max:) enforces. A handler driving the read loop itself is choosing to take the body in unbounded pieces, so bounding it is that handler’s job — count the bytes it keeps, or call collect(max:) instead.