<commit_before>(ns compojure.response
  "Methods for generating Ring response maps"
  (:import java.util.Map
           java.io.File
           [clojure.lang IDeref IFn]))

(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})

(prefer-method render Map IFn)<commit_msg>Added ISeq and InputStream response types<commit_after>(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)
{'fraction_non_alphanumeric': 0.12367303609341826, 'fraction_numerical': 0.012738853503184714, 'mean_word_length': 3.76010101010101, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6509367', 'n_tokens_mistral': 635, 'n_tokens_neox': 591, 'n_words': 223}