1
0
mirror of https://github.com/golang/go synced 2024-11-19 15:05:00 -07:00

http: fix req.Cookie(name) with cookies in one header

Fixes #1974

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4654042
This commit is contained in:
Brad Fitzpatrick 2011-06-20 10:33:07 -07:00
parent 67ec47d1c0
commit da7b96f714
2 changed files with 18 additions and 3 deletions

View File

@ -173,7 +173,7 @@ func readCookies(h Header, filter string) []*Cookie {
if !ok {
return cookies
}
Lines:
for _, line := range lines {
parts := strings.Split(strings.TrimSpace(line), ";", -1)
if len(parts) == 1 && parts[0] == "" {
@ -194,7 +194,7 @@ Lines:
continue
}
if filter != "" && filter != name {
continue Lines
continue
}
val, success := parseCookieValue(val)
if !success {

View File

@ -171,6 +171,21 @@ var readCookiesTests = []struct {
&Cookie{Name: "c2", Value: "v2"},
},
},
{
Header{"Cookie": {"Cookie-1=v$1; c2=v2"}},
"",
[]*Cookie{
&Cookie{Name: "Cookie-1", Value: "v$1"},
&Cookie{Name: "c2", Value: "v2"},
},
},
{
Header{"Cookie": {"Cookie-1=v$1; c2=v2"}},
"c2",
[]*Cookie{
&Cookie{Name: "c2", Value: "v2"},
},
},
}
func TestReadCookies(t *testing.T) {
@ -178,7 +193,7 @@ func TestReadCookies(t *testing.T) {
for n := 0; n < 2; n++ { // to verify readCookies doesn't mutate its input
c := readCookies(tt.Header, tt.Filter)
if !reflect.DeepEqual(c, tt.Cookies) {
t.Errorf("#%d readCookies: have\n%s\nwant\n%s\n", i, toJSON(c), toJSON(tt.Cookies))
t.Errorf("#%d readCookies:\nhave: %s\nwant: %s\n", i, toJSON(c), toJSON(tt.Cookies))
continue
}
}