KapsoEx.Webhook.CacheBodyReader (kapso_ex v0.1.0)

Copy Markdown View Source

A Plug.Parsers body reader that keeps the raw request body, which is needed to verify webhook signatures after the JSON has been parsed.

plug Plug.Parsers,
  parsers: [:json],
  pass: ["*/*"],
  body_reader: {KapsoEx.Webhook.CacheBodyReader, :read_body, []},
  json_decoder: Jason

Then read it back with raw_body/1. Only available when :plug is a dependency of your application.

Summary

Functions

Returns the raw body cached by read_body/2, or nil when it was not read.

Reads the body like Plug.Conn.read_body/2 and stores a copy in conn.private.

Functions

raw_body(conn)

@spec raw_body(Plug.Conn.t()) :: binary() | nil

Returns the raw body cached by read_body/2, or nil when it was not read.

read_body(conn, opts)

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

Reads the body like Plug.Conn.read_body/2 and stores a copy in conn.private.