Fork me on GitHub
#reitit
<
2022-01-10
>
n2o15:01:08

Hello, I am developing against Stripe’s API. To verify the signature (put into the request header by the stripe servers) I need to call Webhook.constructEvent(payload, signature, webhook_access_key) . payload is the raw body of the request, signature is read from the request header, webhook_access_key comes from the API Dashboard of stripe. Now the problem is, that the raw-body of a request is an InputStream, which can only be read once. And the body is read by a middleware (actually I don’t really know which one), which is quite fine (I need the processed information from the request-body), but then I can’t access the raw-body. Do you have any ideas on how I can access the raw-body? Is there a configuration option for muuntaja/format-middleware (I think this one parses the body)? I am using these built-in middlewares: swagger/swagger-feature, parameters/parameters-middleware, muuntaja/format-middleware, coercion/coerce-response-middleware, coercion/coerce-request-middleware, multipart/multipart-middleware Thanks!

athomasoriginal17:01:43

Hey! I faced this problem as well and my solution was that I have a hooks endpoint for stripe which only uses the format-response-middleware because, as you said, you need to be the one who reads the req-body stream. Having said this, note that i’m not actually sure if the reitit team has another way to handle this. I came to this solution after reading 70% of reitit source. Looking back, you can totally add other middleware to get all the other functionality after you handle the raw req-body.

n2o22:01:00

Thanks for your thoughts. One of mine was to read the raw body in a first place, then have it persisted as a string in a :body oder :raw-body field in the request, But it seems a bit weird to read the raw-string before another middleware does so. Thought about it that there must be a smarter way 😄

pinkfrog16:01:06

So for example, if I specify the following under a router`

{:compile coercion/compile-request-coercers}))
Now, how does the middlewares under the router get compiled?