Fork me on GitHub

Morning 🙂 I read somewhere recently (it might have been an old post as I can't find it now) that Ring only supported synchronous handlers, but I can see examples in the docs showing the use of middleware to add support for asynchronous handlers. Something along the lines of:

(defn content-type-response [response content-type]
  (assoc-in response [:headers "Content-Type"] content-type))

(defn wrap-content-type [handler content-type]
      (-> (handler request) (content-type-response content-type)))
    ([request respond raise]
      (handler request #(respond (content-type-response % content-type)) raise))))
Is this example the currently supported/preferred method for adding asynchronous handler support within ring projects or is there some other method that is/will be supported with ring core?


Yes, that example is correct. Async support in Ring is handled by the three-arity handler function. It’s also a good idea to split the middleware into -request and -response functions so that people can manually create their own async interceptors, etc.


Perfect, thanks @U0BKWMG5B 👍