reitit

https://cljdoc.org/d/metosin/reitit/ https://github.com/metosin/reitit/
2020-08-07T15:05:45.430400Z

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 (

firstclassfunc 2020-08-07T15:39:56.431200Z

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

ikitommi 2020-08-07T17:13:56.436600Z

@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

ikitommi 2020-08-07T17:15:27.438900Z

Should the coercion have an option to publish the coerced value?

2020-08-07T17:16:45.440300Z

It could be helpful in many scenarios. My, for instance, is to coerce body and then check the signature of original message

2020-08-07T17:17:41.441100Z

But I need to have original data intact to reconstruct it's signature

ikitommi 2020-08-07T17:22:16.444300Z

original value is not deleted, for body it's in :body-params

2020-08-10T09:02:57.452700Z

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 (

ikitommi 2020-08-10T09:49:32.453Z

for performance reasons, body is read using streaming conversion. Muuntaja could have an option to keep the original data.

ikitommi 2020-08-10T09:51:01.453200Z

keeping the original would be bit slower and would take up ~double amount of mem. So, should be behind an option.

ikitommi 2020-08-10T09:51:14.453400Z

PR welcome

ikitommi 2020-08-10T09:52:32.453600Z

... 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

2020-08-10T10:32:15.453900Z

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

2020-08-10T10:36:58.454100Z

or even better - for ByteArrayInputStream the only missing thing is reseting it after reading. Initial mark is always 0

2020-08-10T10:42:56.454300Z

it is working. So I guess no patch required ) I can reset the stream attached to :body when and only when it is needed

2020-08-10T10:43:12.454500Z

sorry for noise

ikitommi 2020-08-10T11:00:47.454700Z

np, and, didn’t know about stream resetting.

ikitommi 2020-08-07T17:23:25.445400Z

original as in before-coerced.

ikitommi 2020-08-07T17:25:29.446900Z

@gary001 nothing in reitit, but if there is any ring-compatible lib doing that, you can use it.

2020-08-07T20:20:02.449100Z

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?

2020-08-07T20:54:43.450100Z

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?