Req enables cookie storage by default. When the header returned by the server contains Set-Cookie, req will automatically store it by default and automatically set the cookie request header in subsequent requests that need it.

If you need to disable cookies, you can do this:


If necessary, you can also customize the cookie storage, for example, if you want to persist the cookie to a file, you can use it in combination with persistent-cookiejar:

package main

import (
  cookiejar ""

var client *req.Client

func main() {
  jar, err := cookiejar.New(&cookiejar.Options{
    Filename: "cookies.json",
  if err != nil {
    log.Fatalf("failed to create persistent cookiejar: %s\n", err.Error())
  defer jar.Save()
  client = req.C().SetCookieJar(jar).DevMode()

You can even pass in your own cookie storage implementation, such as writing cookies to redis or a database to share cookies across clients.

In most cases, you don’t need to manually set cookies. If you really need it, you can refer to the setting method below.

Manually Set at the Request Level

Use SetCookies to set http cookie for request at the request level:

	// Let's dump the header to see what's going on
client := req.C().EnableDumpAllWithoutResponse()

cookie1 := &http.Cookie{
    Name:     "testcookie1",
    Value:    "testcookie1 value",
    Path:     "/",
    Domain:   "",
    MaxAge:   36000,
    HttpOnly: false,
    Secure:   true,
cookie2 := &http.Cookie{
    Name:     "testcookie2",
    Value:    "testcookie2 value",
    Path:     "/",
    Domain:   "",
    MaxAge:   36000,
    HttpOnly: false,
    Secure:   true,

// Send a request with multiple headers and cookies
    SetCookies(cookie1, cookie2).
:method: GET
:path: /get
:scheme: https
cookie: testcookie1="testcookie1 value"
cookie: testcookie2="testcookie2 value"
accept-encoding: gzip
user-agent: req/v3 (

Also try HTTP/1.1:


    SetCookies(cookie1, cookie2).
GET /get HTTP/1.1
User-Agent: req/v3 (
Cookie: testcookie1="testcookie1 value"; testcookie2="testcookie2 value"
Accept-Encoding: gzip

Manually Set at the Client Level

Similarly, you can use SetCommonCookies to set the common cookies for every request at the client level:

client.SetCommonCookies(cookie1, cookie2, cookie3)

resp1, err := client.R().Get(url1)
resp2, err := client.R().Get(url2)