Merge pull request #471 from metosin/resource-handler-issue

Support not-found-handler with path in resource handler (#464)
This commit is contained in:
Miikka Koskinen 2021-02-19 15:31:55 +02:00 committed by GitHub
commit ff55f85677
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View file

@ -222,7 +222,8 @@
(fn [request]
(let [uri (:uri request)]
(if (str/starts-with? uri path)
(path-or-index-response (subs uri path-size) uri))))
(or (path-or-index-response (subs uri path-size) uri)
(not-found-handler request)))))
(fn [request]
(let [uri (:uri request)
path (-> request :path-params parameter)]

View file

@ -547,7 +547,7 @@
(let [app (ring/ring-handler
(ring/router [])
(ring/routes
(create {:path "/"})
(create {:path "/" :not-found-handler (fn [x] {:status 404 :body "resource-handler"})})
(ring/create-default-handler)))]
(testing test
(testing "different file-types"
@ -568,7 +568,8 @@
(testing "not found"
(let [response (app (request "/not-found"))]
(is (= 404 (:status response)))))
(is (= 404 (:status response)))
(is (= "resource-handler" (:body response)))))
(testing "3-arity"
(let [result (atom nil)
@ -583,7 +584,7 @@
(let [app (ring/ring-handler
(ring/router [])
(ring/routes
(create {:path "/files"})
(create {:path "/files" :not-found-handler (fn [x] {:status 404 :body "resource-handler"})})
(ring/create-default-handler)))
request #(request (str "/files" %))
redirect #(redirect (str "/files" %))]
@ -605,8 +606,12 @@
(is (= (redirect "/docs/index.html") response))))
(testing "not found"
(let [response (app (request "/not-found"))]
(is (= 404 (:status response)))))
(let [response (app {:uri "/not-found" :request-method :get})]
(is (= 404 (:status response)))
(is (= "" (:body response))))
(let [response (app {:uri "/files/not-found" :request-method :get})]
(is (= 404 (:status response)))
(is (= "resource-handler" (:body response)))))
(testing "3-arity"
(let [result (atom nil)