Fix decompressor is not initialized collectly

This commit is contained in:
Iceman 2024-03-19 15:58:15 +09:00
parent c992030a2d
commit 682d1f4fba
2 changed files with 16 additions and 0 deletions

View File

@ -129,6 +129,7 @@ public enum NIOHTTPDecompression {
self.stream.zalloc = nil self.stream.zalloc = nil
self.stream.zfree = nil self.stream.zfree = nil
self.stream.opaque = nil self.stream.opaque = nil
self.inflated = 0
let rc = CNIOExtrasZlib_inflateInit2(&self.stream, encoding.window) let rc = CNIOExtrasZlib_inflateInit2(&self.stream, encoding.window)
guard rc == Z_OK else { guard rc == Z_OK else {

View File

@ -143,6 +143,21 @@ class HTTPResponseDecompressorTest: XCTestCase {
} }
} }
func testDecompressionMultipleWriteWithLimit() {
let channel = EmbeddedChannel()
XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .size(272))).wait())
let headers = HTTPHeaders([("Content-Encoding", "deflate")])
// this compressed payload is 272 bytes long uncompressed
let body = ByteBuffer.of(bytes: [120, 156, 75, 76, 28, 5, 200, 0, 0, 248, 66, 103, 17])
for i in 0..<3 {
XCTAssertNoThrow(try channel.writeInbound(HTTPClientResponsePart.head(.init(version: .init(major: 1, minor: 1), status: .ok, headers: headers))), "\(i)")
XCTAssertNoThrow(try channel.writeInbound(HTTPClientResponsePart.body(body)), "\(i)")
XCTAssertNoThrow(try channel.writeInbound(HTTPClientResponsePart.end(nil)), "\(i)")
}
}
func testDecompression() { func testDecompression() {
let channel = EmbeddedChannel() let channel = EmbeddedChannel()
XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait()) XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait())