Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Using clojure.java.io/resource for resouce-response
  • Loading branch information
weavejester committed Mar 19, 2011
1 parent ba3041a commit 5f12de6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions ring-core/src/ring/util/response.clj
@@ -1,6 +1,7 @@
(ns ring.util.response
"Generate and augment Ring responses."
(:import java.io.File))
(:import java.io.File)
(:require [clojure.java.io :as io]))

(defn redirect
"Returns a Ring response for an HTTP 302 redirect."
Expand Down Expand Up @@ -60,11 +61,11 @@
Options:
:root - take the resource relative to this root"
[path & [opts]]
(let [path (str (:root opts "") "/" path)
path (.replace path "//" "/")
path (.replaceAll path "^/" "")]
(if-let [resource (.. Thread currentThread getContextClassLoader (getResourceAsStream path))]
(response resource))))
(let [path (-> (str (:root opts "") "/" path)
(.replace "//" "/")
(.replaceAll "^/" ""))]
(if-let [resource (io/resource path)]
(response (io/input-stream resource)))))

(defn status
"Returns an updated Ring response with the given status."
Expand Down

0 comments on commit 5f12de6

Please sign in to comment.