# `HttpCookie.Jar`
[🔗](https://github.com/reisub/http_cookie/blob/v0.11.0/lib/http_cookie/jar.ex#L1)

HTTP Cookie Jar

Handles storing cookies from response headers, preparing cookie headers for requests, etc.

Implemented according to [RFC6265](https://datatracker.ietf.org/doc/html/rfc6265)

# `t`

```elixir
@type t() :: %HttpCookie.Jar{cookies: map(), opts: keyword()}
```

# `clear_expired_cookies`

```elixir
@spec clear_expired_cookies(
  jar :: %HttpCookie.Jar{cookies: term(), opts: term()},
  now :: DateTime.t()
) ::
  %HttpCookie.Jar{cookies: term(), opts: term()}
```

Removes cookies which expired before the provided time from the jar.

Uses the current time if no time is provided.

# `clear_session_cookies`

```elixir
@spec clear_session_cookies(jar :: %HttpCookie.Jar{cookies: term(), opts: term()}) ::
  %HttpCookie.Jar{
    cookies: term(),
    opts: term()
  }
```

Removes session cookies from the jar.

Cookies which don't have an explicit expiry time set are considered session cookies and they expire when a user session ends.

# `get_cookie_header_value`

```elixir
@spec get_cookie_header_value(
  jar :: %HttpCookie.Jar{cookies: term(), opts: term()},
  request_url :: URI.t()
) ::
  {:ok, String.t(), %HttpCookie.Jar{cookies: term(), opts: term()}}
  | {:error, :no_matching_cookies}
```

Formats the cookie for sending in a request header for the provided URL.

# `get_matching_cookies`

```elixir
@spec get_matching_cookies(
  jar :: %HttpCookie.Jar{cookies: term(), opts: term()},
  request_url :: URI.t()
) :: {[HttpCookie.t()], %HttpCookie.Jar{cookies: term(), opts: term()}}
```

Gets all the cookies in the store which match the given request URL.

# `new`

```elixir
@spec new(opts :: keyword()) :: %HttpCookie.Jar{cookies: term(), opts: term()}
```

Creates a new empty cookie jar.

## Options

- `:max_cookies` - maximum number of cookies stored, positive integer or :infinity, default: 5_000
- `:max_cookies_per_domain` - maximum number of cookies stored per domain, positive integer or :infinity, default: 100
- `:cookie_opts` - options passed to HttpCookie.from_cookie_string/3

# `put_cookie`

```elixir
@spec put_cookie(
  jar :: %HttpCookie.Jar{cookies: term(), opts: term()},
  cookie :: HttpCookie.t(),
  opts :: list()
) :: %HttpCookie.Jar{cookies: term(), opts: term()}
```

Stores the provided cookie in the jar.

# `put_cookies`

```elixir
@spec put_cookies(
  jar :: %HttpCookie.Jar{cookies: term(), opts: term()},
  cookies :: [HttpCookie.t()]
) ::
  %HttpCookie.Jar{cookies: term(), opts: term()}
```

Stores the provided cookies in the jar.

# `put_cookies_from_headers`

```elixir
@spec put_cookies_from_headers(jar :: t(), request_url :: URI.t(), headers :: list()) ::
  t()
```

Processes the response header list for the given request URL.
Parses set-cookie/set-cookie2 headers and stores valid cookies.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
