Skip to content

Commit

Permalink
Added a test for responding with 304 Not Modified with HTTP compressi…
Browse files Browse the repository at this point in the history
…on (#224)
  • Loading branch information
dimitribouniol authored Jun 18, 2024
1 parent ef36e67 commit 05c36b5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ let package = Package(
.library(name: "NIOHTTPTypesHTTP2", targets: ["NIOHTTPTypesHTTP2"]),
],
dependencies: [
.package(url: "https://github.com/apple/swift-nio.git", from: "2.42.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.67.0"),
.package(url: "https://github.com/apple/swift-nio-http2.git", from: "1.27.0"),
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),
.package(url: "https://github.com/apple/swift-http-types", from: "1.0.0"),
Expand Down
28 changes: 28 additions & 0 deletions Tests/NIOHTTPCompressionTests/HTTPResponseCompressorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,34 @@ class HTTPResponseCompressorTest: XCTestCase {
}
}
}

func testBypassCompressionWhenNotModified() throws {
let channel = EmbeddedChannel()
XCTAssertNoThrow(try channel.pipeline.addHandler(HTTPResponseCompressor()).wait())
defer {
XCTAssertNoThrow(try channel.finish())
}

try sendRequest(acceptEncoding: "deflate;q=2.2, gzip;q=0.3", channel: channel)

let head = HTTPResponseHead(
version: .init(major: 1, minor: 1),
status: .notModified,
headers: .init()
)
try channel.writeOutbound(HTTPServerResponsePart.head(head))
try channel.writeOutbound(HTTPServerResponsePart.end(nil))

while let part = try channel.readOutbound(as: HTTPServerResponsePart.self) {
switch part {
case .head(let head):
XCTAssertEqual(head.headers[canonicalForm: "content-encoding"], [])
case .body:
XCTFail("Unexpected body")
case .end: break
}
}
}
}

extension EventLoopFuture {
Expand Down

0 comments on commit 05c36b5

Please sign in to comment.