ring-clojure / ring

Clojure HTTP server abstraction
MIT License
3.77k stars 520 forks source link

wrap-params "steals" form params in certain cases #360

Closed jacovig closed 5 years ago

jacovig commented 5 years ago

If you have two sets of routes, e.g.

(routes (wrap-defaults apis api-defaults) (wrap-defaults site site-defaults) (route/not-found "Page not found") )

if both 'apis' and 'site' have any POST part, the 'site' POST rules never get the form parameters, unless you use enctype="multipart/form-data". The slurp call in line 27 of ring.middleware.params seems to be unable to extract the parameters from body.

weavejester commented 5 years ago

Unfortunately this is unavoidable. Certain middleware needs to read the request body, and that operation is side-effectful. The only alternative to this is to cache the contents of the request body, which isn't always feasible or desirable.

You can resolve this by placing middleware that reads the request body, which I believe in your case would be wrap-params and wrap-multipart, at the top level.

jacovig commented 5 years ago

Ah, OK. Thanks. What a pitty!

Thank you James.

El lun., 28 ene. 2019 a las 13:56, James Reeves (notifications@github.com) escribió:

Unfortunately this is unavoidable. Certain middleware needs to read the request body, and that operation is side-effectful. The only alternative to this is to cache the contents of the request body, which isn't always feasible or desirable.

You can resolve this by placing middleware that reads the request body, which I believe in your case would be wrap-params and wrap-multipart, at the top level.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ring-clojure/ring/issues/360#issuecomment-458120826, or mute the thread https://github.com/notifications/unsubscribe-auth/AJs2QXyyFED5XgHKlOma4Tru0X_UO0S1ks5vHvOSgaJpZM4aVwwe .