Permalink
Browse files

Using clojure.java.io/resource for resouce-response

  • Loading branch information...
1 parent ba3041a commit 5f12de621f626d16a45de5df9ba7124f7a10c166 @weavejester weavejester committed Mar 19, 2011
Showing with 7 additions and 6 deletions.
  1. +7 −6 ring-core/src/ring/util/response.clj
View
13 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."
@@ -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."

0 comments on commit 5f12de6

Please sign in to comment.