Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (27 sloc) 992 Bytes
(ns compojure.response
"Methods for generating Ring response maps"
(:import java.util.Map
[java.io File InputStream]
[clojure.lang IDeref IFn ISeq]))
(defmulti render
"Given the request map and an arbitrary value x, turn x into a valid HTTP
response map. Dispatches on the type of x."
(fn [_ x] (type x)))
(defmethod render nil [_ _] nil)
(defmethod render String [_ html]
{:status 200
:headers {"Content-Type" "text/html"}
:body html})
(defmethod render Map [_ m]
(merge {:status 200, :headers {}, :body ""} m))
(defmethod render IFn [request handler]
(render request (handler request)))
(defmethod render IDeref [request ref-like]
(render request (deref ref-like)))
(defmethod render File [_ file]
{:status 200, :headers {}, :body file})
(defmethod render ISeq [_ coll]
{:status 200, :headers {}, :body coll})
(defmethod render InputStream [_ stream]
{:status 200, :headers {}, :body stream})
(prefer-method render Map IFn)
Jump to Line
Something went wrong with that request. Please try again.