mirror of
https://github.com/apple/swift-nio-extras.git
synced 2025-06-01 02:34:14 +08:00
Fix decompressor is not initialized collectly
This commit is contained in:
parent
c992030a2d
commit
682d1f4fba
@ -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 {
|
||||||
|
@ -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())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user