bytes(_:length:)
Create an Body
from a Sequence
of bytes.
- 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 : Sendable, Bytes : Sequence, Bytes.Element == UInt8
Parameters
This construction will flatten the bytes into a ByteBuffer
. As a result, the peak memory usage of this construction will be double the size of the original collection. The construction of the ByteBuffer
will be delayed until it’s needed.
Unlike bytes(_:)
, this construction does not assume that the body can be replayed. As a result, if a redirect is encountered that would need us to replay the request body, the redirect will instead not be followed. Prefer bytes(_:)
wherever possible.
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
.