Hi, in the context of reitit-ring — is it possible to get raw body after coercion happen? Right now I’m getting empty InputStream. Looks like it was read by coercer and left empty (
Morning is there anyway to use ring/create-file-handler
to list a directory contents? these directories are dynamically created to don't know a priori. thanks
@delaguardo InputStreams can only read once. In default stack, Muuntaja reads it. The current coercion impls don't publish it, except malli, but only for errors. Here's the code: https://github.com/metosin/reitit/blob/master/modules/reitit-malli/src/reitit/coercion/malli.cljc#L65
Should the coercion have an option to publish the coerced value?
It could be helpful in many scenarios. My, for instance, is to coerce body and then check the signature of original message
But I need to have original data intact to reconstruct it's signature
original value is not deleted, for body it's in :body-params
I made a wrong assumption thinking about coercion. The problem is actually in muuntaja/format-request middleware. It reads from :body, decode the content and add :body-params keyword with decoded content. But the original content (text or bytes) went missing (
for performance reasons, body is read using streaming conversion. Muuntaja could have an option to keep the original data.
keeping the original would be bit slower and would take up ~double amount of mem. So, should be behind an option.
PR welcome
... or, you can add a custom mw before Muuntaja, that slurps the body, pushes the value into request and re-creates the ByteArrayInputStream
into :body
that is how I workaround that atm. Would it be possible to place a mark on a stream before consuming and reset it to that mark after? That could help to not ~double request object size
or even better - for ByteArrayInputStream the only missing thing is reseting it after reading. Initial mark is always 0
it is working. So I guess no patch required ) I can reset the stream attached to :body when and only when it is needed
sorry for noise
np, and, didn’t know about stream resetting.
original as in before-coerced.
@gary001 nothing in reitit, but if there is any ring-compatible lib doing that, you can use it.
Looking at this: https://www.metosin.fi/blog/reitit020/ uploading makes sense when you have {:parameters {:file multipart/temp-file-part}} but what happens when you have additional form fields being submitted? If I try this I get coercion exceptions. Additionally my formdata library is adding an index to the file. Instead of file
is it submitting as file[0]
but that should not matter right?
I think I figured out the first part. The second part with file[0]
still confuses me about how to label that with data-spec. Also, can reitit reload the search on code changes like lein ring server
did?