I have a requirement to check the digest of JSON content sent to a phoenix server. To check the digest the raw body is needed. Is there any way to access the raw content in a plug later in the pipeline than the parsers. I want to add the following Digest verification plug to the end of the pipeline but cannot work out how it accesses the raw content that was sent.
plug Plug.Parsers,
parsers: [:urlencoded, :json],
pass: ["*/*"],
json_decoder: Poison
plug Plug.MethodOverride
plug Plug.Head
plug Plug.VerifyDigest
Copied from my answer here.
You can pass a custom
:body_reader
option toPlug.Parsers
in order to cache the body for later use.You'll want to not read the body before the Parser and instead cache the body to read later from your plug that wants to hash it.
Option:
Example:
It was added in Plug v1.5.1.