Skip to content

Commit

Permalink
sync with monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
joshmossas committed Aug 17, 2024
1 parent 6fc92bf commit 87e23d0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions Sources/ArriClient/ArriClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data> {
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!)
Expand All @@ -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!)
Expand Down

0 comments on commit 87e23d0

Please sign in to comment.