@@ -69,37 +69,24 @@ extension HTTPClient {
6969 self . secure = false
7070
7171 for component in components [ 1 ... ] {
72- if component. starts ( with: " Path " ) , let value = parseComponentValue ( component) {
72+ switch self . parseComponent ( component) {
73+ case ( " path " , . some( let value) ) :
7374 self . path = value
74- continue
75- }
76-
77- if component. starts ( with: " Domain " ) , let value = parseComponentValue ( component) {
75+ case ( " domain " , . some( let value) ) :
7876 self . domain = value
79- continue
80- }
81-
82- if component. starts ( with: " Expires " ) {
77+ case ( " expires " , let value) :
8378 let formatter = DateFormatter ( )
8479 formatter. locale = Locale ( identifier: " en_US " )
8580 formatter. timeZone = TimeZone ( identifier: " GMT " )
8681 formatter. dateFormat = " EEE, dd MMM yyyy HH:mm:ss z "
87- self . expires = self . parseComponentValue ( component) . flatMap { formatter. date ( from: $0) }
88- continue
89- }
90-
91- if component. starts ( with: " Max-Age " ) , let value = parseComponentValue ( component) . flatMap ( Int . init) {
92- self . maxAge = value
93- continue
94- }
95-
96- if component == " Secure " {
82+ self . expires = value. flatMap { formatter. date ( from: $0) }
83+ case ( " max-age " , let value) :
84+ self . maxAge = value. flatMap ( Int . init)
85+ case ( " secure " , nil ) :
9786 self . secure = true
98- continue
99- }
100-
101- if component == " HttpOnly " {
87+ case ( " httponly " , nil ) :
10288 self . httpOnly = true
89+ default :
10390 continue
10491 }
10592 }
@@ -127,14 +114,14 @@ extension HTTPClient {
127114 self . secure = secure
128115 }
129116
130- func parseComponentValue ( _ component: String ) -> String ? {
117+ func parseComponent ( _ component: String ) -> ( String , String ? ) {
131118 let nameAndValue = component. split ( separator: " = " , maxSplits: 1 ) . map {
132119 $0. trimmingCharacters ( in: . whitespaces)
133120 }
134121 if nameAndValue. count == 2 {
135- return nameAndValue [ 1 ]
122+ return ( nameAndValue [ 0 ] . lowercased ( ) , nameAndValue [ 1 ] )
136123 }
137- return nil
124+ return ( nameAndValue [ 0 ] . lowercased ( ) , nil )
138125 }
139126 }
140127}
0 commit comments