        (integer? (:status resp))
        (map? (:headers resp))))
 
-(defn- set-resource-headers
-  "Set Last-Modified and Content-Length for a resource"
-  [resp ^java.net.URL res-url]
-  (when resp
-    (let [ucon (doto (.openConnection res-url)
-                 (.setDoInput false))
-          content-length (.getContentLength ucon)
-          resp (if (neg? content-length)
-                 resp
-                 (header resp "Content-Length" content-length))
-          last-modified (.getLastModified ucon)
-          resp (if (zero? last-modified)
-                 resp
-                 (header resp "Last-Modified" (format-date (java.util.Date. last-modified))))]
-      resp)))
+(defn- connection-content-length [resp conn]
+  (let [content-length (.getContentLength conn)]
+    (if (neg? content-length)
+      resp
+      (header resp "Content-Length" content-length))))
+
+(defn- connection-last-modified [resp conn]
+  (let [last-modified (.getLastModified conn)]
+    (if (zero? last-modified)
+      resp
+      (header resp "Last-Modified" (format-date (Date. last-modified))))))
+
+(defn- file-url [url]
+  (if (= "file" (.getProtocol url))
+    (url-as-file url)))
+
+(defn url-response
+  "Return a response for the supplied URL."
+  [^URL url]
+  (if-let [file (file-url url)]
+    (if-not (.isDirectory file)
+      (-> (response file)
+          (file-content-length)
+          (file-last-modified)))
+    (let [conn (.openConnection url)]
+      (if-let [stream (.getInputStream conn)]
+        (-> (response stream)
+            (connection-content-length conn)
+            (connection-last-modified conn))))))
 
 (defn resource-response
   "Returns a Ring response to serve a packaged resource, or nil if the

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

      (.exists file)
        file)))

(defn- file-content-length [resp]
  (let [file ^File (:body resp)]
    (header resp "Content-Length" (.length file))))

(defn- file-last-modified [resp]
  (let [file ^File (:body resp)]
    (header resp "Last-Modified" (format-date (Date. (.lastModified file))))))

(defn file-response
  "Returns a Ring response to serve a static file, or nil if an appropriate
  file does not exist.
