Solaris.Webhooks.Plug.BodyReader (Solaris v1.0.0)

Copy Markdown View Source

Custom Plug.Parsers body reader that caches the raw request body.

Required for webhook signature verification — the HMAC must be computed over the raw bytes, before any JSON parsing.

Usage

In your endpoint.ex:

plug Plug.Parsers,
  parsers: [:json],
  json_decoder: Jason,
  body_reader: {Solaris.Webhooks.Plug.BodyReader, :read_body, []}

Summary

Functions

Reads the request body and caches it in conn.assigns.raw_body.

Functions

read_body(conn, opts)

@spec read_body(
  Plug.Conn.t(),
  keyword()
) :: {:ok, binary(), Plug.Conn.t()} | {:more, binary(), Plug.Conn.t()}

Reads the request body and caches it in conn.assigns.raw_body.