mirror of
https://github.com/metosin/reitit.git
synced 2025-12-19 09:21:10 +00:00
wrap-coercion doesn't double eval
This commit is contained in:
parent
03e27a2889
commit
40c35a0dfd
1 changed files with 5 additions and 8 deletions
|
|
@ -151,7 +151,7 @@
|
||||||
(defn wrap-coerce-response
|
(defn wrap-coerce-response
|
||||||
"Pluggable response coercion middleware.
|
"Pluggable response coercion middleware.
|
||||||
Expects a :coercion of type `reitit.coercion.protocol/Coercion`
|
Expects a :coercion of type `reitit.coercion.protocol/Coercion`
|
||||||
and :responses from route meta, otherwise does not mount."
|
and :responses from route meta, otherwise will do nothing."
|
||||||
[handler]
|
[handler]
|
||||||
(fn
|
(fn
|
||||||
([request]
|
([request]
|
||||||
|
|
@ -162,20 +162,17 @@
|
||||||
coercion (-> match :meta :coercion)
|
coercion (-> match :meta :coercion)
|
||||||
opts (-> match :meta :opts)]
|
opts (-> match :meta :opts)]
|
||||||
(if (and coercion responses)
|
(if (and coercion responses)
|
||||||
(let [coercers (response-coercers coercion responses opts)
|
(let [coercers (response-coercers coercion responses opts)]
|
||||||
coerced (coerce-response coercers request response)]
|
(coerce-response coercers request response))
|
||||||
(coerce-response coercers request (handler request)))
|
|
||||||
(handler request))))
|
(handler request))))
|
||||||
([request respond raise]
|
([request respond raise]
|
||||||
(let [response (handler request)
|
(let [method (:request-method request)
|
||||||
method (:request-method request)
|
|
||||||
match (ring/get-match request)
|
match (ring/get-match request)
|
||||||
responses (-> match :result method :meta :responses)
|
responses (-> match :result method :meta :responses)
|
||||||
coercion (-> match :meta :coercion)
|
coercion (-> match :meta :coercion)
|
||||||
opts (-> match :meta :opts)]
|
opts (-> match :meta :opts)]
|
||||||
(if (and coercion responses)
|
(if (and coercion responses)
|
||||||
(let [coercers (response-coercers coercion responses opts)
|
(let [coercers (response-coercers coercion responses opts)]
|
||||||
coerced (coerce-response coercers request response)]
|
|
||||||
(handler request #(respond (coerce-response coercers request %))))
|
(handler request #(respond (coerce-response coercers request %))))
|
||||||
(handler request respond raise))))))
|
(handler request respond raise))))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue