 (ns ring.util.response
   "Generate and augment Ring responses."
-  (:import java.io.File)
+  (:import java.io.File java.util.Date java.net.URL)
   (:use [ring.util.time :only (format-date)])
   (:require [clojure.java.io :as io]
             [clojure.string :as str]))

    :root - take the resource relative to this root"
  [path & [opts]]
  (let [path (-> (str (:root opts "") "/" path)
    (.replace "//" "/")
    (.replaceAll "^/" ""))]
    (if-let [resource (io/resource path)]
      (->
        (if (= "file" (.getProtocol resource))
          (let [file (url-as-file resource)]
            (if-not (.isDirectory file)
              (response file)))
          ; a jar url ending in a slash is by definition a directory
          (when-not (.endsWith path "/")
            ; paths to directories with trailing slashes return an URL, but a nil InputStream
            (when-let [in (io/input-stream resource)]
              (response in))))
        (set-resource-headers resource)))))

          (char)
          (str))))))

(defn content-type
  "Returns an updated Ring response with the a Content-Type header corresponding
  to the given content-type."
