Skip to content

Commit

Permalink
Increased maxResponseBytes to avoid NIOTooManyBytesError (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Clafou authored Mar 11, 2024
1 parent 649f5de commit bad39b4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Sources/IppClient/HttpClient+Ipp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down

0 comments on commit bad39b4

Please sign in to comment.