wrap-coercion doesn't double eval

This commit is contained in:
Tommi Reiman 2017-10-02 08:06:49 +03:00
parent 03e27a2889
commit 40c35a0dfd

View file

@ -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))))))