Permalink
Browse files

Added option map argument to wrap-file middleware

  • Loading branch information...
1 parent e2a08b2 commit 6b93eadf327fb160ef956c4f30dab00d839cc5dc @weavejester weavejester committed Sep 20, 2010
Showing with 16 additions and 10 deletions.
  1. +12 −10 ring-core/src/ring/middleware/file.clj
  2. +4 −0 ring-core/test/ring/middleware/file_test.clj
View
22 ring-core/src/ring/middleware/file.clj
@@ -15,14 +15,16 @@
(defn wrap-file
"Wrap an app such that the directory at the given root-path is checked for a
static file with which to respond to the request, proxying the request to the
- wrapped app if such a file does not exist."
- [app ^String root-path]
+ wrapped app if such a file does not exist.
+
+ An map of options may be optionally specified. These options will be passed
+ to the ring.util.response/file-response function."
+ [app ^String root-path & [opts]]
(ensure-dir root-path)
- (fn [req]
- (if-not (= :get (:request-method req))
- (app req)
- (let [path (.substring (codec/url-decode (:uri req)) 1)]
- (or
- (response/file-response path
- {:root root-path :index-files? true :html-files? true})
- (app req))))))
+ (let [opts (merge {:root root-path, :index-files? true} opts)]
+ (fn [req]
+ (if-not (= :get (:request-method req))
+ (app req)
+ (let [path (.substring (codec/url-decode (:uri req)) 1)]
+ (or (response/file-response path opts)
+ (app req)))))))
View
4 ring-core/test/ring/middleware/file_test.clj
@@ -34,3 +34,7 @@
(is (= {} headers))
(is (= foo-html body))))
+(deftest test-wrap-file-no-index
+ (let [app (wrap-file (constantly :response) public-dir {:index-files? false})
+ resp (app {:request-method :get :uri "/"})]
+ (is (= :response resp))))

0 comments on commit 6b93ead

Please sign in to comment.