View Source SlackRequest.BodyReader (SlackRequest v0.3.1)

Intended to be used as the :body_reader option of Plug.Parsers.

Keeps the raw body in a private conn assign so that it can be used later in the call stack for verification of the Slack HQ HTTP request timestamp and signtaure.

Note that default Plug.Conn.read_body/2 reads the body once but doesn't keep it for later further inspection.

Example

# endpoint.ex
Plug.Parsers,
  ...
  body_reader: {SlackRequest.BodyReader, :read_and_cache_body, []}

So later, one can get the cached body with:

SlackRequest.BodyReader.cached_body(conn)

Summary

Functions

@spec cached_body(Plug.Conn.t()) :: binary()
This function is deprecated. Please use SlackRequest.BodyReader.cached_body/1 instead.
@spec get_raw_body(Plug.Conn.t()) :: binary()
Link to this function

read_and_cache_body(conn, opts \\ [])

View Source
@spec read_and_cache_body(Plug.Conn.t(), Keyword.t()) ::
  {:ok, binary(), Plug.Conn.t()}
  | {:more, binary(), Plug.Conn.t()}
  | {:error, term()}
Link to this function

read_body(conn, opts \\ [])

View Source
This function is deprecated. Please use SlackRequest.BodyReader.read_and_cached_body/2 instead.
@spec read_body(Plug.Conn.t(), Keyword.t()) ::
  {:ok, binary(), Plug.Conn.t()}
  | {:more, binary(), Plug.Conn.t()}
  | {:error, term()}