Skip to content

Commit a2046c2

Browse files
committed
update cookie test
1 parent 2ad236e commit a2046c2

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

components/ws-proxy/pkg/proxy/cookies.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,27 +49,37 @@ func readCookies(h http.Header, filter string) []*http.Cookie {
4949
if filter != "" && filter != name {
5050
continue
5151
}
52-
val, ok := parseCookieValue(val, true)
52+
val, quoted, ok := parseCookieValue(val, true)
5353
if !ok {
5454
continue
5555
}
56-
cookies = append(cookies, &http.Cookie{Name: name, Value: val})
56+
cookies = append(cookies, &http.Cookie{Name: name, Value: val, Quoted: quoted})
5757
}
5858
}
5959
return cookies
6060
}
6161

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) {
6372
// Strip the quotes, if present.
6473
if allowDoubleQuote && len(raw) > 1 && raw[0] == '"' && raw[len(raw)-1] == '"' {
6574
raw = raw[1 : len(raw)-1]
75+
quoted = true
6676
}
6777
for i := 0; i < len(raw); i++ {
6878
if !validCookieValueByte(raw[i]) {
69-
return "", false
79+
return "", quoted, false
7080
}
7181
}
72-
return raw, true
82+
return raw, quoted, true
7383
}
7484

7585
func validCookieValueByte(b byte) bool {

0 commit comments

Comments
 (0)