Closed
Description
Hello,
The following test fails:
package foo
import (
"net/http"
"net/http/cookiejar"
"net/url"
"testing"
)
func TestIPDomain(t *testing.T) {
u, err := url.Parse("http://127.0.0.1/")
if err != nil {
t.Fatal(err)
}
jar, err := cookiejar.New(nil)
if err != nil {
t.Fatal(err)
}
c := &http.Cookie{Name: "foo", Value: "bar", Domain: "127.0.0.1"}
jar.SetCookies(u, []*http.Cookie{c})
cs := jar.Cookies(u)
if len(cs) != 1 {
t.Fatalf("Got %v cookies, expected 1\n", len(cs))
} else if cs[0].Name != "foo" || cs[0].Value != "bar" {
t.Fatal("Invalid cookie name/value")
}
}
Further inspection shows that it fails with errNoHostname here:
go/src/net/http/cookiejar/jar.go
Lines 447 to 452 in 7f0be1f
I believe the comment refers to RFC6265 5.1.3. It states that the domain string must either be identical with the string it's matched against, OR that all of the three subsequently listed conditions are met, one of which are that the string being matched must be a host name.
In the case of the matched string being an IP address and the domain string being the same IP address, the first condition is met. I therefor believe that L447-L452 should be removed.