@@ -33,53 +33,37 @@ func readCookies(h http.Header, filter string) []*http.Cookie {
3333
3434 var part string
3535 for len (line ) > 0 { // continue since we have rest
36- if splitIndex := strings .Index (line , ";" ); splitIndex > 0 {
37- part , line = line [:splitIndex ], line [splitIndex + 1 :]
38- } else {
39- part , line = line , ""
40- }
36+ part , line , _ = strings .Cut (line , ";" )
4137 part = textproto .TrimString (part )
42- if len ( part ) == 0 {
38+ if part == "" {
4339 continue
4440 }
45- name , val := part , ""
46- if j := strings .Index (part , "=" ); j >= 0 {
47- name , val = name [:j ], name [j + 1 :]
48- }
41+ name , val , _ := strings .Cut (part , "=" )
42+ name = textproto .TrimString (name )
4943 if filter != "" && filter != name {
5044 continue
5145 }
52- val , quoted , ok := parseCookieValue (val , true )
46+ val , ok := parseCookieValue (val , true )
5347 if ! ok {
5448 continue
5549 }
56- cookies = append (cookies , & http.Cookie {Name : name , Value : val , Quoted : quoted })
50+ cookies = append (cookies , & http.Cookie {Name : name , Value : val })
5751 }
5852 }
5953 return cookies
6054}
6155
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 ) {
56+ func parseCookieValue (raw string , allowDoubleQuote bool ) (string , bool ) {
7257 // Strip the quotes, if present.
7358 if allowDoubleQuote && len (raw ) > 1 && raw [0 ] == '"' && raw [len (raw )- 1 ] == '"' {
7459 raw = raw [1 : len (raw )- 1 ]
75- quoted = true
7660 }
7761 for i := 0 ; i < len (raw ); i ++ {
7862 if ! validCookieValueByte (raw [i ]) {
79- return "" , quoted , false
63+ return "" , false
8064 }
8165 }
82- return raw , quoted , true
66+ return raw , true
8367}
8468
8569func validCookieValueByte (b byte ) bool {
0 commit comments