Skip to content

Commit 7e0ebe2

Browse files
committed
changed bytes from a computed property to a func. Removed 1Mb expected bytes
1 parent 8f1e2ea commit 7e0ebe2

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse.swift

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,18 @@ extension HTTPClientResponse {
141141
@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
142142
extension HTTPClientResponse {
143143
/// Response body as `ByteBuffer`.
144-
public var bytes: ByteBuffer {
145-
get async throws {
146-
let expectedBytes = headers
147-
.first(name: "content-length")
148-
.flatMap(Int.init) ?? 1024 * 1024
149-
return try await body.collect(upTo: expectedBytes)
144+
/// - Returns: Bytes collected over time
145+
public func bytes() async throws -> ByteBuffer {
146+
if let expectedBytes = self.headers.first(name: "content-length").flatMap(Int.init) {
147+
return try await self.body.collect(upTo: expectedBytes)
150148
}
149+
150+
var data = [UInt8]()
151+
for try await var buffer in self.body {
152+
data = data + (buffer.readBytes(length: buffer.readableBytes) ?? [])
153+
}
154+
155+
return ByteBuffer(bytes: data)
151156
}
152157
}
153158

0 commit comments

Comments
 (0)