Ring async handler support
burhanloey opened this issue · comments
Hi!
Thank you for this awesome library.
Is there any plan to support Ring async handler for make-handler
(or make-async-handler
)?
The handler is a 3-arity function as stated here.
I guess this is not needed anymore, at least for me.
I ended up with something like this:
(defn- wrap-response [handler]
(fn
([request]
(compojure.response/render (handler request) request))
([request respond raise]
(compojure.response/send (handler request) request respond raise))))
(defn make-async-handler
"Create a Ring async handler from the route definition data structure. Matches a
handler from the uri in the request, and invokes it with the request as a
parameter."
([route]
(fn [{:keys [uri path-info request-method] :as req} respond raise]
(let [path (or path-info uri)
{:keys [handler]} (apply match-route route path req)
handler' (wrap-response handler)]
(handler' req respond raise)))))