Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: [swift] add maxBodyBytes parameter to allow for adjusting the maximum bytes a response body can take up #86

Merged
Merged
Changes from all 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
11 changes: 9 additions & 2 deletions languages/swift/swift-client/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
Loading