Skip to content

Commit

Permalink
Changes required by compress-nio v0.6.0 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler authored Jun 14, 2023
1 parent 9b85f83 commit 828d282
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
4 changes: 2 additions & 2 deletions Sources/HummingbirdCompression/RequestDecompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions Sources/HummingbirdCompression/ResponseCompression.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 11 additions & 11 deletions Tests/HummingbirdCompressionTests/CompressionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand All @@ -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<Void>] = 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
Expand All @@ -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<Void>] = 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
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down

0 comments on commit 828d282

Please sign in to comment.