Remove the `path=/` restriction

This commit is contained in:
islishude 2024-05-22 08:41:40 +08:00
parent e581799756
commit 7df8738b80
2 changed files with 2 additions and 3 deletions

View File

@ -319,8 +319,8 @@ func (c *Cookie) Valid() error {
} }
} }
if c.Partitioned { if c.Partitioned {
if !c.Secure || c.Path != "/" { if !c.Secure {
return errors.New("http: partitioned cookies must be set with Secure and Path=/") return errors.New("http: partitioned cookies must be set with Secure")
} }
} }
return nil return nil

View File

@ -574,7 +574,6 @@ func TestCookieValid(t *testing.T) {
{&Cookie{Name: ""}, false}, {&Cookie{Name: ""}, false},
{&Cookie{Name: "invalid-value", Value: "foo\"bar"}, false}, {&Cookie{Name: "invalid-value", Value: "foo\"bar"}, false},
{&Cookie{Name: "invalid-path", Path: "/foo;bar/"}, false}, {&Cookie{Name: "invalid-path", Path: "/foo;bar/"}, false},
{&Cookie{Name: "invalid-path-for-partitioned", Value: "foo", Path: "/bar", Secure: true, Partitioned: true}, false},
{&Cookie{Name: "invalid-secure-for-partitioned", Value: "foo", Path: "/", Secure: false, Partitioned: true}, false}, {&Cookie{Name: "invalid-secure-for-partitioned", Value: "foo", Path: "/", Secure: false, Partitioned: true}, false},
{&Cookie{Name: "invalid-domain", Domain: "example.com:80"}, false}, {&Cookie{Name: "invalid-domain", Domain: "example.com:80"}, false},
{&Cookie{Name: "invalid-expiry", Value: "", Expires: time.Date(1600, 1, 1, 1, 1, 1, 1, time.UTC)}, false}, {&Cookie{Name: "invalid-expiry", Value: "", Expires: time.Date(1600, 1, 1, 1, 1, 1, 1, time.UTC)}, false},