ExLine.Webhook.BodyReader (ExLine v0.1.0)

Copy Markdown View Source

A custom Plug.Parsers body reader that caches the raw request body in conn.assigns[:raw_body], so ExLine.Webhook.Plug can verify the LINE signature after the JSON parser has consumed the stream.

Wire it into your endpoint's Plug.Parsers:

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

Ref: https://hexdocs.pm/plug/Plug.Parsers.html#module-custom-body-reader

Summary

Functions

read_body(conn, opts)

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