@@ -49,27 +49,37 @@ func readCookies(h http.Header, filter string) []*http.Cookie {
49
49
if filter != "" && filter != name {
50
50
continue
51
51
}
52
- val , ok := parseCookieValue (val , true )
52
+ val , quoted , ok := parseCookieValue (val , true )
53
53
if ! ok {
54
54
continue
55
55
}
56
- cookies = append (cookies , & http.Cookie {Name : name , Value : val })
56
+ cookies = append (cookies , & http.Cookie {Name : name , Value : val , Quoted : quoted })
57
57
}
58
58
}
59
59
return cookies
60
60
}
61
61
62
- func parseCookieValue (raw string , allowDoubleQuote bool ) (string , bool ) {
62
+ // parseCookieValue parses a cookie value according to RFC 6265.
63
+ // If allowDoubleQuote is true, parseCookieValue will consider that it
64
+ // is parsing the cookie-value;
65
+ // otherwise, it will consider that it is parsing a cookie-av value
66
+ // (cookie attribute-value).
67
+ //
68
+ // It returns the parsed cookie value, a boolean indicating whether the
69
+ // parsing was successful, and a boolean indicating whether the parsed
70
+ // value was enclosed in double quotes.
71
+ func parseCookieValue (raw string , allowDoubleQuote bool ) (value string , quoted , ok bool ) {
63
72
// Strip the quotes, if present.
64
73
if allowDoubleQuote && len (raw ) > 1 && raw [0 ] == '"' && raw [len (raw )- 1 ] == '"' {
65
74
raw = raw [1 : len (raw )- 1 ]
75
+ quoted = true
66
76
}
67
77
for i := 0 ; i < len (raw ); i ++ {
68
78
if ! validCookieValueByte (raw [i ]) {
69
- return "" , false
79
+ return "" , quoted , false
70
80
}
71
81
}
72
- return raw , true
82
+ return raw , quoted , true
73
83
}
74
84
75
85
func validCookieValueByte (b byte ) bool {
0 commit comments