Skip to content

Commit

Permalink
Add example code to Plug.Conn.Cookies.encode/2 (#1256)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinschweikert authored Dec 22, 2024
1 parent b469e1c commit b2c0d64
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/plug/conn/cookies.ex
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ defmodule Plug.Conn.Cookies do

@doc """
Encodes the given cookies as expected in a response header.
## Examples
iex> encode("key1", %{value: "value1"})
"key1=value1; path=/; HttpOnly"
iex> encode("key1", %{value: "value1", secure: true, path: "/example", http_only: false})
"key1=value1; path=/example; secure"
"""
def encode(key, opts \\ %{}) when is_map(opts) do
value = Map.get(opts, :value)
Expand Down

0 comments on commit b2c0d64

Please sign in to comment.