From dd74b408fc46cfb6a8c61b3fbb4c382735936063 Mon Sep 17 00:00:00 2001 From: Joshua Sosso Date: Sat, 17 Aug 2024 13:07:49 -0500 Subject: [PATCH] add maxBodyBytes parameter to allow the body maxBytes to be adjusted (#86) --- .../swift-client/Sources/ArriClient/ArriClient.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/languages/swift/swift-client/Sources/ArriClient/ArriClient.swift b/languages/swift/swift-client/Sources/ArriClient/ArriClient.swift index 6f9b59da..2c17ffa5 100644 --- a/languages/swift/swift-client/Sources/ArriClient/ArriClient.swift +++ b/languages/swift/swift-client/Sources/ArriClient/ArriClient.swift @@ -245,11 +245,18 @@ public protocol ArriRequestDelegate { } public struct DefaultRequestDelegate: ArriRequestDelegate { + var maxBodyBytes: Int = 1024 * 1024 public init() {} + /// Accumulates `Body` of `ByteBuffer`s into a single `ByteBuffer`. + /// - Parameters: + /// - maxBodyBytes: The maximum number of bytes that a single response body can take up. Default is 1048576 (1MB) + public init(maxBodyBytes: Int) { + self.maxBodyBytes = maxBodyBytes + } public func handleHTTPRequest(request: ArriHTTPRequest) async throws -> ArriHTTPResponse { let httpRequest = self.prepareHttpRequest(request: request) let response = try await HTTPClient.shared.execute(httpRequest, timeout: .seconds(5)) - let responseBody = try? await response.body.collect(upTo: 1024 * 1024) + let responseBody = try? await response.body.collect(upTo: maxBodyBytes) var responseData: Data? if responseBody != nil { responseData = Data(buffer: responseBody!) @@ -274,7 +281,7 @@ public struct DefaultRequestDelegate: ArriRequestDelegate { body: response.body )) } - let responseBody = try? await response.body.collect(upTo: 1024 * 1024) + let responseBody = try? await response.body.collect(upTo: maxBodyBytes) var responseData: Data? if responseBody != nil { responseData = Data(buffer: responseBody!)