Skip to content

304 Not Modified Broken with Response Compression Enabled #2737

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/NIOHTTP1/HTTPTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,7 @@ public enum HTTPResponseStatus: Sendable {
.switchingProtocols,
.processing,
.noContent,
.notModified,
.custom where (code < 200) && (code >= 100):
return false
default:
Expand Down
12 changes: 12 additions & 0 deletions Tests/NIOHTTP1Tests/HTTPResponseEncoderTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class HTTPResponseEncoderTests: XCTestCase {
writtenData.assertContainsOnly("HTTP/1.1 204 No Content\r\ncontent-length: 0\r\n\r\n")
}

func testNoContentLengthHeadersFor304() throws {
let headers = HTTPHeaders([("content-length", "0")])
let writtenData = sendResponse(withStatus: .notModified, andHeaders: headers)
writtenData.assertContainsOnly("HTTP/1.1 304 Not Modified\r\n\r\n")
}

func testNoTransferEncodingHeadersFor101() throws {
let headers = HTTPHeaders([("transfer-encoding", "chunked")])
let writtenData = sendResponse(withStatus: .switchingProtocols, andHeaders: headers)
Expand Down Expand Up @@ -153,6 +159,12 @@ class HTTPResponseEncoderTests: XCTestCase {
writtenData.assertContainsOnly("HTTP/1.1 204 No Content\r\ntransfer-encoding: chunked\r\n\r\n")
}

func testNoTransferEncodingHeadersFor304() throws {
let headers = HTTPHeaders([("transfer-encoding", "chunked")])
let writtenData = sendResponse(withStatus: .notModified, andHeaders: headers)
writtenData.assertContainsOnly("HTTP/1.1 304 Not Modified\r\n\r\n")
}

func testNoChunkedEncodingForHTTP10() throws {
let channel = EmbeddedChannel()
defer {
Expand Down