Permalink
Please sign in to comment.
Showing
with
0 additions
and 38 deletions.
1
README.md
18
ring-core/src/ring/middleware/static.clj
| @@ -1,18 +0,0 @@ | ||
| -(ns ring.middleware.static | ||
| - "Static file serving, more selective than ring.middleware.file." | ||
| - (:use ring.middleware.file)) | ||
| - | ||
| -(defn wrap-static | ||
| - "Like ring.file, but takes an additional statics, a coll of Strings that will | ||
| - be used to test incoming requests uris. If a uri begins with any of the | ||
| - strings in the statics coll, the middleware will check to see if a file can be | ||
| - served from the public-dir before proxying back to the given app; if the uri | ||
| - does not correspond to one of these strings, the middleware proxies the | ||
| - request directly back to the app without touching the filesystem." | ||
| - [app public-dir statics] | ||
| - (let [app-with-file (wrap-file app public-dir)] | ||
| - (fn [req] | ||
| - (let [^String uri (:uri req)] | ||
| - (if (some #(.startsWith uri %) statics) | ||
| - (app-with-file req) | ||
| - (app req)))))) |
19
ring-core/test/ring/middleware/test/static.clj
| @@ -1,19 +0,0 @@ | ||
| -(ns ring.middleware.test.static | ||
| - (:use clojure.test | ||
| - ring.middleware.static) | ||
| - (:import java.io.File)) | ||
| - | ||
| -(def public-dir "test/ring/assets") | ||
| -(def foo-html "test/ring/assets/foo.html") | ||
| -(def nested-foo-html "test/ring/assets/bars/foo.html") | ||
| -(def statics ["/foo.html" "/bars/"]) | ||
| - | ||
| -(def app (wrap-static (constantly {:body :dynamic}) public-dir statics)) | ||
| - | ||
| -(defn app-response-body [uri] | ||
| - (:body (app {:request-method :get :uri uri}))) | ||
| - | ||
| -(deftest test-wrap-static-smoke | ||
| - (is (= (File. foo-html) (app-response-body "/foo.html"))) | ||
| - (is (= (File. nested-foo-html) (app-response-body "/bars/foo.html"))) | ||
| - (is (= :dynamic (app-response-body "/not/static")))) |
0 comments on commit
b6aaae1