Commit da7b96f7 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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

Fixes #1974

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4654042
parent 67ec47d1
......@@ -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 {
......
......@@ -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
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment