WardrikHTTP.BodyReader (wardrik_http v0.1.0-rc.1)

Copy Markdown

Keeps a request's raw body while Plug.Parsers reads it, so webhook signatures can be checked over the exact bytes.

Use it if your app parses bodies before WardrikHTTP sees them:

plug Plug.Parsers,
  parsers: [:json],
  json_decoder: JSON,
  body_reader: {WardrikHTTP.BodyReader, :read_body, []}

Summary

Functions

Returns the kept raw body, or nil if none was kept.

Reads the body as Plug.Conn.read_body/2 does, and keeps a copy.

Functions

kept(conn)

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

Returns the kept raw body, or nil if none was kept.

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 as Plug.Conn.read_body/2 does, and keeps a copy.