async-http-client
async-http-client copied to clipboard
Two handy extensions to work with HTTPClientResponse body
Two extensions for HTTPClientResponse
to avoid boilerplate code.
Reading a response data currently:
let expectedBytes = headers.first(name: "content-length").flatMap(Int.init) ?? 1024 * 1024
var bytes = try await body.collect(upTo: expectedBytes)
if let data = bytes.readData(length: bytes.readableBytes) {
// handle data
}
With the extension:
if let data = try await response.data(upTo: 1024*1024) {
// handle data
}
Additionally an extension for bytes
. Currently:
let expectedBytes = headers.first(name: "content-length").flatMap(Int.init) ?? 1024 * 1024
var bytes = try await body.collect(upTo: expectedBytes)
With the extension:
var bytes = try await response.bytes(upTo: 1024*1024)