Skip to content

Commit 2624ccc

Browse files
authored
Use case-insensitive comparision rather than lowercasing (#308)
Motivation: When getting the canonical form of headers we check whether the header name is 'set-cookie' to avoid splitting values which are not safe to split. This check is done against a `lowercased()` version of the header name. However, we don't need to produce a new `String` here as we already have a case insensitive string comparision function. Modifications: - Add a test to verify that getting the canonical form of "set-cookie" does not split any header values - Switch to `isEqualCaseInsensitiveASCIIBytes` Result: More tests, cheaper comparision.
1 parent cce39c3 commit 2624ccc

File tree

3 files changed

+84
-75
lines changed

3 files changed

+84
-75
lines changed

Sources/NIOHPACK/HPACKHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public struct HPACKHeaders: ExpressibleByDictionaryLiteral {
256256
}
257257

258258
// It's not safe to split Set-Cookie on comma.
259-
guard name.lowercased() != "set-cookie" else {
259+
if name.isEqualCaseInsensitiveASCIIBytes(to: "set-cookie") {
260260
return result
261261
}
262262

Tests/NIOHPACKTests/HPACKCodingTests+XCTest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ extension HPACKCodingTests {
3737
("testHPACKHeadersSubscript", testHPACKHeadersSubscript),
3838
("testHPACKHeadersCanonicalFormStripsWhitespace", testHPACKHeadersCanonicalFormStripsWhitespace),
3939
("testHPACKHeadersCanonicalFormDropsEmptyStrings", testHPACKHeadersCanonicalFormDropsEmptyStrings),
40+
("testHPACKHeadersCanonicalFormSetCookie", testHPACKHeadersCanonicalFormSetCookie),
4041
("testHPACKHeadersFirst", testHPACKHeadersFirst),
4142
("testHPACKHeadersExpressedByDictionaryLiteral", testHPACKHeadersExpressedByDictionaryLiteral),
4243
("testHPACKHeadersAddingSequenceOfPairs", testHPACKHeadersAddingSequenceOfPairs),

0 commit comments

Comments
 (0)