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)
Two extensions for
HTTPClientResponse
to avoid boilerplate code.Reading a response data currently:
With the extension:
Additionally an extension for
bytes
. Currently:With the extension: