stream(_:length:)

Create an Body from an AsyncSequence of bytes.

HTTPClientRequest.swift:317
iOS
13.0+
macOS
10.15+
tvOS
13.0+
watchOS
6.0+
@preconcurrency static func stream<Bytes>(_ bytes: Bytes, length: Length) -> HTTPClientRequest.Body where Bytes : Sendable, Bytes : AsyncSequence, Bytes.Element == UInt8

Parameters

bytes

The bytes of the request body.

length

The length of the request body.

This construction will consume 4MB chunks from the Bytes and send them at once. This optimizes for AsyncSequences where larger chunks are buffered up and available without actually suspending, such as those provided by FileHandle.

Caution should be taken with this method to ensure that the length is correct. Incorrect lengths will cause unnecessary runtime failures. Setting length to unknown will trigger the upload to use chunked Transfer-Encoding, while using known(_:) will use Content-Length.