From aa5970f23a0d6e326622b958f2fd157877bd2b86 Mon Sep 17 00:00:00 2001 From: Cory Benfield Date: Wed, 11 Feb 2026 08:02:30 +0000 Subject: [PATCH] Use a smaller max buffer size on 32-bit platforms --- Sources/AsyncHTTPClient/HTTPHandler.swift | 3 ++- .../HTTP1ClientChannelHandlerTests.swift | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/Sources/AsyncHTTPClient/HTTPHandler.swift b/Sources/AsyncHTTPClient/HTTPHandler.swift index 20df597ca..940cdf40f 100644 --- a/Sources/AsyncHTTPClient/HTTPHandler.swift +++ b/Sources/AsyncHTTPClient/HTTPHandler.swift @@ -543,7 +543,8 @@ public final class ResponseAccumulator: HTTPClientResponseDelegate { let requestMethod: HTTPMethod let requestHost: String - static let maxByteBufferSize = Int(UInt32.max) + // This is either UInt32.max, or Int.max on platforms where that value is smaller. + static let maxByteBufferSize = Int(exactly: UInt32.max) ?? Int(Int32.max) /// Maximum size in bytes of the HTTP response body that ``ResponseAccumulator`` will accept /// until it will abort the request and throw an ``ResponseTooBigError``. diff --git a/Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift b/Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift index f35670e1b..401c14ff0 100644 --- a/Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift +++ b/Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift @@ -946,6 +946,16 @@ class HTTP1ClientChannelHandlerTests: XCTestCase { ] ) } + + func testDefaultMaxBufferSize() { + if MemoryLayout.size == 8 { + XCTAssertEqual(ResponseAccumulator.maxByteBufferSize, Int(UInt32.max)) + } else if MemoryLayout.size == 4 { + XCTAssertEqual(ResponseAccumulator.maxByteBufferSize, Int(Int32.max)) + } else { + XCTFail("What platform is this?") + } + } } final class TestBackpressureWriter: Sendable {