{"id":15686381,"url":"https://github.com/nhatthm/go-cookiejar","last_synced_at":"2025-07-26T16:08:35.342Z","repository":{"id":79220532,"uuid":"605146770","full_name":"nhatthm/go-cookiejar","owner":"nhatthm","description":"Persistent Cookie Jar for HTTP Client","archived":false,"fork":false,"pushed_at":"2025-04-22T07:19:26.000Z","size":86,"stargazers_count":17,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-07T17:05:24.294Z","etag":null,"topics":["afero","aferofs","cookie","cookiejar","go","golang","http","http-client","http-cookie","http-cookies"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nhatthm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-22T14:46:18.000Z","updated_at":"2025-04-22T07:09:34.000Z","dependencies_parsed_at":"2023-12-07T11:31:18.815Z","dependency_job_id":"cd9b64c3-c51c-4e0b-bdf9-90d3aafc9d3a","html_url":"https://github.com/nhatthm/go-cookiejar","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.18181818181818177","last_synced_commit":"e2d0c5b4d30557eb181ab41f40cab2a9531c0f18"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/nhatthm/go-cookiejar","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cookiejar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cookiejar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cookiejar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cookiejar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nhatthm","download_url":"https://codeload.github.com/nhatthm/go-cookiejar/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nhatthm%2Fgo-cookiejar/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267191036,"owners_count":24050318,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-26T02:00:08.937Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["afero","aferofs","cookie","cookiejar","go","golang","http","http-client","http-cookie","http-cookies"],"created_at":"2024-10-03T17:39:05.361Z","updated_at":"2025-07-26T16:08:35.322Z","avatar_url":"https://github.com/nhatthm.png","language":"Go","funding_links":["https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY"],"categories":[],"sub_categories":[],"readme":"# Cookiejar\n\n[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/go-cookiejar)](https://github.com/nhatthm/go-cookiejar/releases/latest)\n[![Build Status](https://github.com/nhatthm/go-cookiejar/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/go-cookiejar/actions/workflows/test.yaml)\n[![codecov](https://codecov.io/gh/nhatthm/go-cookiejar/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/go-cookiejar)\n[![Go Report Card](https://goreportcard.com/badge/go.nhat.io/cookiejar)](https://goreportcard.com/report/go.nhat.io/cookiejar)\n[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/go.nhat.io/cookiejar)\n[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\nThe Persistent Cookiejar is a fork of [`net/http/cookiejar`](https://pkg.go.dev/net/http/cookiejar) which also implements methods for persisting the cookies to\na filesystem and retrieving them using [`spf13/afero`](https://github.com/spf13/afero)\n\n## Prerequisites\n\n- `Go \u003e= 1.23`\n\n## Install\n\n```bash\ngo get go.nhat.io/cookiejar\n```\n\n## Usage\n\nConstruct the cookiejar with the following options:\n\n| Option                 | Description                                                                                                                         |   Default Value   |\n|:-----------------------|:------------------------------------------------------------------------------------------------------------------------------------|:-----------------:|\n| `WithFilePath`         | The path to the file to store the cookies                                                                                           | `\"cookies.json\"`  |\n| `WithFilePerm`         | The file permission to use for persisting the cookies                                                                               |      `0600`       |\n| `WithAutoSync`         | Whether to automatically sync the cookies to the file after each request                                                            |      `false`      |\n| `WithLogger`           | The logger to use for logging                                                                                                       |      No log       |\n| `WithFs`               | The filesystem to use for persisting the cookies                                                                                    | `afero.NewOsFs()` |\n| `WithSerDer`           | The serializer/deserializer to use for persisting the cookies                                                                       |      `json`       |\n| `WithPublicSuffixList` | The public suffix list to use for cookie domain matching \u003c/br\u003e All users of cookiejar should import `golang.org/x/net/publicsuffix` |       `nil`       |\n\nExample:\n\n```go\npackage example\n\nimport (\n\t\"net/http\"\n\n\t\"go.nhat.io/cookiejar\"\n)\n\nfunc newClient() *http.Client {\n\tjar := cookiejar.NewPersistentJar(\n\t\tcookiejar.WithFilePath(\"/path/to/cookies.json\"),\n\t\tcookiejar.WithFilePerm(0755),\n\t\tcookiejar.WithAutoSync(true),\n\t)\n\n\treturn \u0026http.Client{\n\t\tJar: jar,\n\t}\n}\n\n```\n\n## Examples\n\n```go\npackage cookiejar_test\n\nimport (\n\t\"fmt\"\n\t\"log\"\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"net/url\"\n\t\"os\"\n\t\"path/filepath\"\n\n\t\"go.nhat.io/cookiejar\"\n)\n\nfunc ExampleNewPersistentJar() {\n\ttempDir, err := os.MkdirTemp(os.TempDir(), \"example\")\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tdefer os.RemoveAll(tempDir)\n\n\tcookiesFile := filepath.Join(tempDir, \"cookies\")\n\n\t// Start a server to give us cookies.\n\tts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {\n\t\tif cookie, err := r.Cookie(\"Flavor\"); err != nil {\n\t\t\thttp.SetCookie(w, \u0026http.Cookie{Name: \"Flavor\", Value: \"Chocolate Chip\"})\n\t\t} else {\n\t\t\tcookie.Value = \"Oatmeal Raisin\"\n\t\t\thttp.SetCookie(w, cookie)\n\t\t}\n\t}))\n\tdefer ts.Close()\n\n\tu, err := url.Parse(ts.URL)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tjar := cookiejar.NewPersistentJar(\n\t\tcookiejar.WithFilePath(cookiesFile),\n\t\tcookiejar.WithAutoSync(true),\n\t\t// All users of cookiejar should import \"golang.org/x/net/publicsuffix\"\n\t\tcookiejar.WithPublicSuffixList(publicsuffix.List),\n\t)\n\n\tclient := \u0026http.Client{\n\t\tJar: jar,\n\t}\n\n\tif _, err = client.Get(u.String()); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(\"After 1st request:\")\n\tfor _, cookie := range jar.Cookies(u) {\n\t\tfmt.Printf(\"  %s: %s\\n\", cookie.Name, cookie.Value)\n\t}\n\n\tif _, err = client.Get(u.String()); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tfmt.Println(\"After 2nd request:\")\n\tfor _, cookie := range jar.Cookies(u) {\n\t\tfmt.Printf(\"  %s: %s\\n\", cookie.Name, cookie.Value)\n\t}\n\n\t// Output:\n\t// After 1st request:\n\t//   Flavor: Chocolate Chip\n\t// After 2nd request:\n\t//   Flavor: Oatmeal Raisin\n}\n```\n\n## Donation\n\nIf this project help you reduce time to develop, you can give me a cup of coffee :)\n\n### Paypal donation\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY)\n\n\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;\u0026nbsp;or scan this\n\n\u003cimg src=\"https://user-images.githubusercontent.com/1154587/113494222-ad8cb200-94e6-11eb-9ef3-eb883ada222a.png\" width=\"147px\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-cookiejar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnhatthm%2Fgo-cookiejar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnhatthm%2Fgo-cookiejar/lists"}