mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
Second fix to #209
This commit is contained in:
parent
d2d5019d0f
commit
62f908d988
2 changed files with 7 additions and 2 deletions
|
|
@ -121,7 +121,7 @@
|
|||
([] (redirect-trailing-slash-handler {:method :both}))
|
||||
([{:keys [method]}]
|
||||
(letfn [(maybe-redirect [request path]
|
||||
(if (r/match-by-path (::r/router request) path)
|
||||
(if (and (seq path) (r/match-by-path (::r/router request) path))
|
||||
{:status (if (= (:request-method request) :get) 301 308)
|
||||
:headers {"Location" path}
|
||||
:body ""}))
|
||||
|
|
|
|||
|
|
@ -241,7 +241,9 @@
|
|||
|
||||
(deftest trailing-slash-handler-test
|
||||
(let [ok {:status 200, :body "ok"}
|
||||
routes [["/slash-less" {:get (constantly ok),
|
||||
routes [["" {:summary "unreachable"
|
||||
:get (constantly ok)}]
|
||||
["/slash-less" {:get (constantly ok),
|
||||
:post (constantly ok)}]
|
||||
["/with-slash/" {:get (constantly ok),
|
||||
:post (constantly ok)}]]]
|
||||
|
|
@ -269,6 +271,9 @@
|
|||
(ring/router routes)
|
||||
(ring/redirect-trailing-slash-handler {:method :strip}))]
|
||||
|
||||
(testing "stripping to empty string doesn't match"
|
||||
(is (= nil (:status (app {:request-method :get, :uri "/"})))))
|
||||
|
||||
(testing "exact matches work"
|
||||
(is (= ok (app {:request-method :get, :uri "/slash-less"})))
|
||||
(is (= ok (app {:request-method :post, :uri "/slash-less"})))
|
||||
|
|
|
|||
Loading…
Reference in a new issue