Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,19 @@ extension HTTPClientResponse {
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension HTTPClientResponse {
/// Response body as `ByteBuffer`.
public var bytes: ByteBuffer {
get async throws {
let expectedBytes = headers
.first(name: "content-length")
.flatMap(Int.init) ?? 1024 * 1024
return try await body.collect(upTo: expectedBytes)
}
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
@usableFromInline
typealias TransactionBody = NIOThrowingAsyncSequenceProducer<
Expand Down
11 changes: 11 additions & 0 deletions Sources/AsyncHTTPClient/FoundationExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ extension HTTPClient.Body {
return self.bytes(data)
}
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension HTTPClientResponse {
/// Response body as `Data`.
public var data: Data? {
get async throws {
var bytes = try await bytes
return bytes.readData(length: bytes.readableBytes)
}
}
}