From bad39b4b832b83bf9361e0f5ae7bfa1f9ea90ff8 Mon Sep 17 00:00:00 2001 From: Seb Molines <992689+Clafou@users.noreply.github.com> Date: Mon, 11 Mar 2024 12:23:19 +0000 Subject: [PATCH] Increased maxResponseBytes to avoid NIOTooManyBytesError (#1) * Increased maxBytes to avoid NIOTooManyBytesError Calling getPrinterAttributes to request "printer-description", "job-template" and "media-col-database" (as per example at https://www.pwg.org/ipp/ippguide.html#querying-the-printer-attributes ) on Simulated InkJet results in an NIOTooManyBytesError. Raised the hardcoded max value to 1 MB instead of 20 KB and made it an optional param. * Renamed maxBytes Renamed maxBytes to maxResponseBytes --- Sources/IppClient/HttpClient+Ipp.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/IppClient/HttpClient+Ipp.swift b/Sources/IppClient/HttpClient+Ipp.swift index ef845f6..22ffc81 100644 --- a/Sources/IppClient/HttpClient+Ipp.swift +++ b/Sources/IppClient/HttpClient+Ipp.swift @@ -13,7 +13,8 @@ public extension HTTPClient { _ request: IppRequest, authentication: IppAuthentication? = nil, data: consuming HTTPClientRequest.Body? = nil, - timeout: TimeAmount = .seconds(10) + timeout: TimeAmount = .seconds(10), + maxResponseBytes: Int = 1024 * 1024 ) async throws -> IppResponse { let httpRequest = try HTTPClientRequest(ippRequest: request, authentication: authentication, data: data) let httpResponse = try await execute(httpRequest, timeout: timeout) @@ -22,7 +23,7 @@ public extension HTTPClient { throw IppHttpResponseError(response: httpResponse) } - var buffer = try await httpResponse.body.collect(upTo: 20 * 1024) + var buffer = try await httpResponse.body.collect(upTo: maxResponseBytes) return try IppResponse(buffer: &buffer) } }