bytes(_:length:)

Create an Body from a Collection of bytes.

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

Parameters

bytes

The bytes of the request body.

length

The length of the request body.

This construction will flatten the bytes into a ByteBuffer in chunks of ~4MB. As a result, the peak memory usage of this construction will be a small multiple of ~4MB. The construction of the ByteBuffer will be delayed until it’s needed.

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.