Inngest.CacheBodyReader (Inngest v0.3.0)

Copy Markdown View Source

A custom Plug parser for caching raw request bodies.

Inngest verifies inbound request signatures against the raw request body. Plug.Parsers consumes that body while parsing, so this reader stores the bytes in connection private data before the parser discards them.

Use paths: to limit caching to the Inngest endpoint when the parser runs globally in a Phoenix endpoint:

plug Plug.Parsers,
  parsers: [:urlencoded, :json],
  pass: ["*/*"],
  body_reader: {Inngest.CacheBodyReader, :read_body, [[paths: ["/api/inngest"]]]},
  json_decoder: Phoenix.json_library()

Plug's multipart parser does not use the :body_reader option.

Summary

Types

read_result()

@type read_result() ::
  {:ok, binary(), Plug.Conn.t()}
  | {:more, binary(), Plug.Conn.t()}
  | {:error, term()}

Functions

read_body(conn, opts)

@spec read_body(
  Plug.Conn.t(),
  keyword()
) :: read_result()

read_body(conn, opts, reader_opts)

@spec read_body(Plug.Conn.t(), keyword(), keyword()) :: read_result()

read_cached_body(conn)

@spec read_cached_body(Plug.Conn.t()) :: binary()