Skip to content

Commit 52ed9d1

Browse files
authored
Use a smaller max buffer size on 32-bit platforms (#886)
Resolves #884
1 parent 67ac92d commit 52ed9d1

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/AsyncHTTPClient/HTTPHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,8 @@ public final class ResponseAccumulator: HTTPClientResponseDelegate {
543543
let requestMethod: HTTPMethod
544544
let requestHost: String
545545

546-
static let maxByteBufferSize = Int(UInt32.max)
546+
// This is either UInt32.max, or Int.max on platforms where that value is smaller.
547+
static let maxByteBufferSize = Int(exactly: UInt32.max) ?? Int(Int32.max)
547548

548549
/// Maximum size in bytes of the HTTP response body that ``ResponseAccumulator`` will accept
549550
/// until it will abort the request and throw an ``ResponseTooBigError``.

Tests/AsyncHTTPClientTests/HTTP1ClientChannelHandlerTests.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,16 @@ class HTTP1ClientChannelHandlerTests: XCTestCase {
946946
]
947947
)
948948
}
949+
950+
func testDefaultMaxBufferSize() {
951+
if MemoryLayout<Int>.size == 8 {
952+
XCTAssertEqual(ResponseAccumulator.maxByteBufferSize, Int(UInt32.max))
953+
} else if MemoryLayout<Int>.size == 4 {
954+
XCTAssertEqual(ResponseAccumulator.maxByteBufferSize, Int(Int32.max))
955+
} else {
956+
XCTFail("What platform is this?")
957+
}
958+
}
949959
}
950960

951961
final class TestBackpressureWriter: Sendable {

0 commit comments

Comments
 (0)