Skip to content

Commit

Permalink
support periods in directive keys (#2372)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed May 28, 2020
1 parent 77b84cf commit 6dfdb34
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Sources/Vapor/HTTP/Headers/HTTPHeaders+Directive.swift
Expand Up @@ -224,9 +224,12 @@ private extension Character {
static var underscore: Self {
.init("_")
}
static var period: Self {
.init(".")
}

var isDirectiveKey: Bool {
self.isLetter || self.isNumber || self == .dash || self == .underscore
self.isLetter || self.isNumber || self == .dash || self == .underscore || self == .period
}
}

Expand Down
9 changes: 9 additions & 0 deletions Tests/VaporTests/HTTPHeaderTests.swift
Expand Up @@ -176,6 +176,15 @@ final class HTTPHeaderValueTests: XCTestCase {
XCTAssertEqual(headers.cookie?["oauth2_consent_csrf"]?.string, "MTU4NjkzNzgwMnxEdi1CQkFFQ180SUFBUkFCRUFBQVB2LUNBQUVHYzNSeWFXNW5EQVlBQkdOemNtWUdjM1J5YVc1bkRDSUFJR1ExWVRnM09USmhOamRsWXpSbU4yRmhOR1UwTW1KaU5tRXpPRGczTmpjMHweHbVecAf193ev3_1Tcf60iY9jSsq5-IQxGTyoztRTfg==")
}

func testCookie_dotParsing() throws {
let headers = HTTPHeaders([
("cookie", "cookie_one=1;cookie.two=2")
])

XCTAssertEqual(headers.cookie?["cookie_one"]?.string, "1")
XCTAssertEqual(headers.cookie?["cookie.two"]?.string, "2")
}

func testMediaTypeMainTypeCaseInsensitive() throws {
let lower = HTTPMediaType(type: "foo", subType: "")
let upper = HTTPMediaType(type: "FOO", subType: "")
Expand Down

0 comments on commit 6dfdb34

Please sign in to comment.