diff --git a/Package.swift b/Package.swift index d0d5bc3..f18f07a 100644 --- a/Package.swift +++ b/Package.swift @@ -11,7 +11,7 @@ let package = Package( ], dependencies: [ .package(url: "https://github.com/hummingbird-project/hummingbird.git", from: "1.0.0"), - .package(url: "https://github.com/adam-fowler/compress-nio.git", from: "0.5.0"), + .package(url: "https://github.com/adam-fowler/compress-nio.git", from: "0.6.0"), .package(url: "https://github.com/apple/swift-nio.git", from: "2.32.1"), ], targets: [ diff --git a/Sources/HummingbirdCompression/RequestDecompression.swift b/Sources/HummingbirdCompression/RequestDecompression.swift index 2c6ba12..9c5fb73 100644 --- a/Sources/HummingbirdCompression/RequestDecompression.swift +++ b/Sources/HummingbirdCompression/RequestDecompression.swift @@ -209,9 +209,9 @@ class HTTPRequestDecompressHandler: ChannelInboundHandler, RemovableChannelHandl for encoding in contentEncodingHeaders { switch encoding { case "gzip": - return CompressionAlgorithm.gzip.decompressor() + return CompressionAlgorithm.gzip().decompressor case "deflate": - return CompressionAlgorithm.deflate.decompressor() + return CompressionAlgorithm.zlib().decompressor default: break } diff --git a/Sources/HummingbirdCompression/ResponseCompression.swift b/Sources/HummingbirdCompression/ResponseCompression.swift index fe7fa1b..4e97333 100644 --- a/Sources/HummingbirdCompression/ResponseCompression.swift +++ b/Sources/HummingbirdCompression/ResponseCompression.swift @@ -243,15 +243,15 @@ class HTTPResponseCompressHandler: ChannelDuplexHandler, RemovableChannelHandler if gzipQValue > 0 || deflateQValue > 0 { if gzipQValue > deflateQValue { - return (compressor: CompressionAlgorithm.gzip.compressor(), name: "gzip") + return (compressor: CompressionAlgorithm.gzip().compressor, name: "gzip") } else { - return (compressor: CompressionAlgorithm.deflate.compressor(), name: "deflate") + return (compressor: CompressionAlgorithm.zlib().compressor, name: "deflate") } } else if anyQValue > 0 { // Though gzip is usually less well compressed than deflate, it has slightly // wider support because it's unabiguous. We therefore default to that unless // the client has expressed a preference. - return (compressor: CompressionAlgorithm.gzip.compressor(), name: "gzip") + return (compressor: CompressionAlgorithm.gzip().compressor, name: "gzip") } return nil diff --git a/Tests/HummingbirdCompressionTests/CompressionTests.swift b/Tests/HummingbirdCompressionTests/CompressionTests.swift index 635e487..07a98b0 100644 --- a/Tests/HummingbirdCompressionTests/CompressionTests.swift +++ b/Tests/HummingbirdCompressionTests/CompressionTests.swift @@ -41,7 +41,7 @@ class HummingBirdCompressionTests: XCTestCase { let testBuffer = self.randomBuffer(size: Int.random(in: 64000...261_335)) try app.XCTExecute(uri: "/echo", method: .GET, headers: ["accept-encoding": "gzip"], body: testBuffer) { response in var body = response.body - let uncompressed = try body?.decompress(with: .gzip) + let uncompressed = try body?.decompress(with: .gzip()) XCTAssertEqual(uncompressed, testBuffer) } } @@ -59,7 +59,7 @@ class HummingBirdCompressionTests: XCTestCase { let testBuffer = self.randomBuffer(size: 261_335) try app.XCTExecute(uri: "/echo", method: .GET, headers: ["accept-encoding": "gzip"], body: testBuffer) { response in var body = response.body - let uncompressed = try body?.decompress(with: .gzip) + let uncompressed = try body?.decompress(with: .gzip()) XCTAssertEqual(uncompressed, testBuffer) } } @@ -80,7 +80,7 @@ class HummingBirdCompressionTests: XCTestCase { if Bool.random() == true { return app.xct.execute(uri: "/echo", method: .GET, headers: ["accept-encoding": "gzip"], body: buffer).flatMapThrowing { response in var body = try XCTUnwrap(response.body) - let uncompressed = try body.decompress(with: .gzip) + let uncompressed = try body.decompress(with: .gzip()) XCTAssertEqual(uncompressed, buffer) } } else { @@ -107,7 +107,7 @@ class HummingBirdCompressionTests: XCTestCase { if Bool.random() == true { return app.xct.execute(uri: "/echo", method: .GET, headers: ["accept-encoding": "gzip"], body: buffer).flatMapThrowing { response in var body = try XCTUnwrap(response.body) - let uncompressed = try body.decompress(with: .gzip) + let uncompressed = try body.decompress(with: .gzip()) XCTAssertEqual(uncompressed, buffer) } } else { @@ -131,7 +131,7 @@ class HummingBirdCompressionTests: XCTestCase { let testBuffer = self.randomBuffer(size: 261_335) var testBufferCopy = testBuffer - let compressedBuffer = try testBufferCopy.compress(with: .gzip) + let compressedBuffer = try testBufferCopy.compress(with: .gzip()) try app.XCTExecute(uri: "/echo", method: .GET, headers: ["content-encoding": "gzip"], body: compressedBuffer) { response in XCTAssertEqual(response.body, testBuffer) } @@ -149,7 +149,7 @@ class HummingBirdCompressionTests: XCTestCase { let testBuffer = self.randomBuffer(size: 261_335) var testBufferCopy = testBuffer - let compressedBuffer = try testBufferCopy.compress(with: .gzip) + let compressedBuffer = try testBufferCopy.compress(with: .gzip()) try app.XCTExecute(uri: "/echo", method: .GET, headers: ["content-encoding": "gzip"], body: compressedBuffer) { response in XCTAssertEqual(response.body, testBuffer) } @@ -176,7 +176,7 @@ class HummingBirdCompressionTests: XCTestCase { func compress(_ buffer: ByteBuffer) throws -> ByteBuffer { var b = buffer - return try b.compress(with: .gzip) + return try b.compress(with: .gzip()) } let buffer1 = self.randomBuffer(size: 256_000) let buffer2 = self.randomBuffer(size: 256_000) @@ -202,7 +202,7 @@ class HummingBirdCompressionTests: XCTestCase { defer { app.XCTStop() } let buffers = (0..<32).map { _ in self.randomBuffer(size: Int.random(in: 16...512_000)) } - let compressedBuffers = try buffers.map { b -> (ByteBuffer, ByteBuffer) in var b = b; return try (b, b.compress(with: .gzip)) } + let compressedBuffers = try buffers.map { b -> (ByteBuffer, ByteBuffer) in var b = b; return try (b, b.compress(with: .gzip())) } let futures: [EventLoopFuture] = compressedBuffers.map { buffers in if Bool.random() == true { return app.xct.execute(uri: "/echo", method: .GET, headers: ["content-encoding": "gzip"], body: buffers.1).map { response in @@ -228,7 +228,7 @@ class HummingBirdCompressionTests: XCTestCase { defer { app.XCTStop() } let buffers = (0..<32).map { _ in self.randomBuffer(size: Int.random(in: 16...512_000)) } - let compressedBuffers = try buffers.map { b -> (ByteBuffer, ByteBuffer) in var b = b; return try (b, b.compress(with: .gzip)) } + let compressedBuffers = try buffers.map { b -> (ByteBuffer, ByteBuffer) in var b = b; return try (b, b.compress(with: .gzip())) } let futures: [EventLoopFuture] = compressedBuffers.map { buffers in if Bool.random() == true { return app.xct.execute(uri: "/echo", method: .GET, headers: ["content-encoding": "gzip"], body: buffers.1).map { response in @@ -271,7 +271,7 @@ class HummingBirdCompressionTests: XCTestCase { let testBuffer = self.randomBuffer(size: 150_000) var testBufferCopy = testBuffer - let compressedBuffer = try testBufferCopy.compress(with: .gzip) + let compressedBuffer = try testBufferCopy.compress(with: .gzip()) try app.XCTExecute(uri: "/echo", method: .GET, headers: ["content-encoding": "gzip"], body: compressedBuffer) { response in XCTAssertEqual(response.status, .payloadTooLarge) } @@ -293,7 +293,7 @@ class HummingBirdCompressionTests: XCTestCase { testBuffer.writeInteger(UInt8(i & 0xFF)) } var testBufferCopy = testBuffer - let compressedBuffer = try testBufferCopy.compress(with: .gzip) + let compressedBuffer = try testBufferCopy.compress(with: .gzip()) try app.XCTExecute(uri: "/echo", method: .GET, headers: ["content-encoding": "gzip"], body: compressedBuffer) { response in XCTAssertEqual(response.status, .payloadTooLarge) }