mozcookie reads and writes files in the Mozilla/Netscape HTTP Cookie File format
Find a file
Sebastien Binet cf784b7371 all: migrate to codeberg
Signed-off-by: Sebastien Binet <binet@cern.ch>
2025-03-04 16:05:29 +01:00
.github/workflows all: add ci 2022-04-21 11:55:32 +02:00
testdata all: first import 2022-04-21 11:29:13 +02:00
go.mod all: migrate to codeberg 2025-03-04 16:05:29 +01:00
LICENSE all: first import 2022-04-21 11:29:13 +02:00
mozcookie.go all: migrate to codeberg 2025-03-04 16:05:29 +01:00
mozcookie_example_test.go all: migrate to codeberg 2025-03-04 16:05:29 +01:00
mozcookie_test.go all: handle dos2unix 2022-04-21 12:01:38 +02:00
read.go all: handle partial cookie lines 2024-10-03 16:22:16 +02:00
README.md all: migrate to codeberg 2025-03-04 16:05:29 +01:00
write.go all: first import 2022-04-21 11:29:13 +02:00

mozcookie

GoDoc CI License

mozcookie is a simple package providing tools to read and write cookies from and to files in the Netscape HTTP Cookie File format.

For more informations about this format, see:

Example

	cookies := []*http.Cookie{
		&http.Cookie{Name: "cookie-1", Value: "v$1", Domain: "golang.org", Path: "/pkg/"},
		&http.Cookie{Name: "cookie-2", Value: "v$2", Domain: "golang.org", Path: "/pkg/", Secure: true},
		&http.Cookie{Name: "cookie-3", Value: "v$3", Domain: "golang.org", Path: "/pkg/", HttpOnly: true},
	}
	err := mozcookie.Write("testdata/cookie.txt", cookies)
	if err != nil {
		log.Fatalf("could not write cookies: %+v", err)
	}

	cs, err := mozcookie.Read("testdata/cookie.txt")
	if err != nil {
		log.Fatalf("could not read cookies: %+v", err)
	}

	fmt.Printf("cookies:\n")
	for _, c := range cs {
		fmt.Printf("%s: %q\n", c.Name, c.Value)
	}

License

mozcookie is released under the BSD-3 license.