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
@type read_result() :: {:ok, binary(), Plug.Conn.t()} | {:more, binary(), Plug.Conn.t()} | {:error, term()}
Functions
@spec read_body( Plug.Conn.t(), keyword() ) :: read_result()
@spec read_body(Plug.Conn.t(), keyword(), keyword()) :: read_result()
@spec read_cached_body(Plug.Conn.t()) :: binary()