diff --git a/Sources/NIOHTTPCompression/HTTPDecompression.swift b/Sources/NIOHTTPCompression/HTTPDecompression.swift index d99b65b..fe36dd6 100644 --- a/Sources/NIOHTTPCompression/HTTPDecompression.swift +++ b/Sources/NIOHTTPCompression/HTTPDecompression.swift @@ -129,6 +129,7 @@ public enum NIOHTTPDecompression { self.stream.zalloc = nil self.stream.zfree = nil self.stream.opaque = nil + self.inflated = 0 let rc = CNIOExtrasZlib_inflateInit2(&self.stream, encoding.window) guard rc == Z_OK else { diff --git a/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift b/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift index b42e629..ee7460f 100644 --- a/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift +++ b/Tests/NIOHTTPCompressionTests/HTTPResponseDecompressorTest.swift @@ -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() { let channel = EmbeddedChannel() XCTAssertNoThrow(try channel.pipeline.addHandler(NIOHTTPResponseDecompressor(limit: .none)).wait())