Permalink
Browse files

Fixes to compojure.response/resource

  • Loading branch information...
1 parent 33847bd commit 513f41b5a18c706268b95940d8a0a75347fc2114 @weavejester committed Jan 30, 2011
Showing with 16 additions and 9 deletions.
  1. +16 −9 src/compojure/response.clj
View
@@ -31,18 +31,25 @@
InputStream
(render [this _] (response this)))
+(defn- servlet-resource-stream [context path]
+ (.getResourceAsStream context (str "/" path)))
+
+(defn- thread-resource-stream [path]
+ (.. Thread
+ currentThread
+ getContextClassLoader
+ (getResourceAsStream path)))
+
+(defn- resource-stream [path request]
+ (if-let [context (:servlet-context request)]
+ (servlet-resource-stream context path)
+ (thread-resource-stream path)))
+
(deftype Resource [path]
Renderable
(render [_ request]
- (let [path (.. path (replace "//" "/")
- (replaceAll "^/" ""))]
- (response
- (if-let [context (:servlet-context request)]
- (.getResourceAsStream context path)
- (.. Thread
- currentThread
- getContextClassLoader
- (getResourceAsStream path)))))))
+ (if-let [stream (resource-stream path request)]
+ (response stream))))
(defn resource
"Create a resource response."

0 comments on commit 513f41b

Please sign in to comment.