Browse files

Fixed exception on resource-response (issue #38)

  • Loading branch information...
1 parent 3b06648 commit 8b0dd7d69a94eca694c9ac770a64b1cb607cf1b7 @weavejester weavejester committed Oct 10, 2011
Showing with 9 additions and 5 deletions.
  1. +5 −4 ring-core/src/ring/util/response.clj
  2. +4 −1 ring-core/test/ring/util/test/response.clj
View
9 ring-core/src/ring/util/response.clj
@@ -72,10 +72,11 @@
(.replace "//" "/")
(.replaceAll "^/" ""))]
(if-let [resource (io/resource path)]
- (response
- (if (= "file" (.getProtocol resource))
- (io/as-file resource)
- (io/input-stream resource))))))
+ (if (= "file" (.getProtocol resource))
+ (let [file (io/as-file resource)]
+ (if-not (.isDirectory file)
+ (response file)))
+ (response (io/input-stream resource))))))
(defn status
"Returns an updated Ring response with the given status."
View
5 ring-core/test/ring/util/test/response.clj
@@ -66,4 +66,7 @@
(is (.startsWith (slurp body) "(ns ring.util.response")))
(let [body (:body (resource-response "clojure/java/io.clj"))]
(is (instance? InputStream body))
- (is (.contains (slurp body) "clojure.java.io")))))
+ (is (.contains (slurp body) "clojure.java.io"))))
+
+ (testing "resource is a directory"
+ (is (nil? (resource-response "/ring/assets")))))

0 comments on commit 8b0dd7d

Please sign in to comment.