Skip to content

Commit

Permalink
support underscore in HTTP header directive key (#2266)
Browse files Browse the repository at this point in the history
  • Loading branch information
tanner0101 committed Mar 26, 2020
1 parent 9f68951 commit cac009e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/Vapor/HTTP/HTTPHeaders+Directive.swift
Expand Up @@ -5,9 +5,9 @@ extension HTTPHeaders {

var description: String {
if let parameter = self.parameter {
return "\(self.value)=\(parameter)"
return "Directive(value: \(self.value.debugDescription), parameter: \(parameter.debugDescription))"
} else {
return "\(self.value)"
return "Directive(value: \(self.value.debugDescription))"
}
}

Expand Down Expand Up @@ -221,9 +221,12 @@ private extension Character {
static var comma: Self {
.init(",")
}
static var underscore: Self {
.init("_")
}

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

Expand Down
Expand Up @@ -155,4 +155,13 @@ final class HTTPHeaderValueTests: XCTestCase {
XCTAssertEqual(headers.contentDisposition?.name, "fieldName")
XCTAssertEqual(headers.contentDisposition?.filename, "filename.jpg")
}

func testCookie_parsing() throws {
let headers = HTTPHeaders([
("cookie", "vapor-session=0FuTYcHmGw7Bz1G4HiF+EA==; _ga=GA1.1.500315824.1585154561; _gid=GA1.1.500224287.1585154561")
])
XCTAssertEqual(headers.cookie?["vapor-session"]?.string, "0FuTYcHmGw7Bz1G4HiF+EA==")
XCTAssertEqual(headers.cookie?["_ga"]?.string, "GA1.1.500315824.1585154561")
XCTAssertEqual(headers.cookie?["_gid"]?.string, "GA1.1.500224287.1585154561")
}
}

0 comments on commit cac009e

Please sign in to comment.