-
Notifications
You must be signed in to change notification settings - Fork 604
Description
We're implementing HTTP signatures in our Elixir applications. We need to be able to hash the request body in order to verify the overall request signature. As Cowboy only allows the body to be read once and Plug does not keep the raw bytes from the socket anywhere doing this is impossible when using any of the Plug parsers.
Verifying the signature of incoming requests is a widespread pattern (Twilio, Stripe, etc) and IMO something any web library should not make it difficult to do.
I am proposing some solutions but want to begin a general discussion around design with the maintainers before writing code:
-
Plug.Conn.read_body/2should store the raw body somewhere in there Conn's structure. If so where? Another field on the struct, or as private data? (This could allow read_body to be called multiple times idempotently during a request, hiding the leaky cowboy abstraction). -
Plug.Conn.read_body/2should allow the registration of callback functions that are called with the tuple return value of the function.