PhoenixApiToolkit.CacheBodyReader.cache_and_read_body
You're seeing just the function
cache_and_read_body
, go back to PhoenixApiToolkit.CacheBodyReader module for more information.
Specs
cache_and_read_body(Plug.Conn.t(), Keyword.t()) :: {:ok, binary(), Plug.Conn.t()} | {:more, binary(), Plug.Conn.t()} | {:error, term()}
Read the request body and cache the raw version in the conn. The raw version
can be accessed with get_raw_request_body/1
.
Examples
use Plug.Test
import PhoenixApiToolkit.CacheBodyReader
import PhoenixApiToolkit.TestHelpers
# the body is read and cached
iex> {:ok, raw_body, conn} = conn(:get, "/hello") |> put_raw_body("some rawness") |> cache_and_read_body()
iex> raw_body
"some rawness"
iex> conn.assigns[:raw_body]
["some rawness"]
# Plug.Conn.read_body/2 is used in the background, opts and responses responses are passed through
iex> result = conn(:get, "/hello") |> put_raw_body("some rawness") |> cache_and_read_body(length: 1)
iex> result |> elem(0)
:more