The documentation for :body_reader
in Plug.Parsers
includes this example:
defmodule CacheBodyReader do
def read_body(conn, opts) do
{:ok, body, conn} = Plug.Conn.read_body(conn, opts)
conn = update_in(conn.assigns[:raw_body], &[body | (&1 || [])])
{:ok, body, conn}
end
end
Why does this example use
conn = update_in(conn.assigns[:raw_body], &[body | (&1 || [])])
rather than
conn = Plug.Conn.assign(conn, :raw_body, body)
Does the assign need to be an array? Are there other plugs that use conn.assigns[:raw_body]
, and don’t want it to be overwritten?