Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net/http/cookiejar: implement concurrent-safe Clear method #70259

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/net/http/cookiejar/jar.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,3 +544,13 @@ func (j *Jar) domainAndType(host, domain string) (string, bool, error) {

return domain, false, nil
}

// Clear deletes all stored cookies.
//
// Clear is safe for concurrent use.
func (j *Jar) Clear() {
j.mu.Lock()
defer j.mu.Unlock()
clear(j.entries)
j.nextSeqNum = 0
}
8 changes: 8 additions & 0 deletions src/net/http/cookiejar/jar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,14 @@ func TestBasics(t *testing.T) {
}
}

func TestClear(t *testing.T) {
jar := newTestJar()
for _, test := range basicsTests {
test.run(t, jar)
jar.Clear()
}
}

// updateAndDeleteTests contains jarTests which must be performed on the same
// Jar.
var updateAndDeleteTests = [...]jarTest{
Expand Down