mirror of
https://github.com/metosin/reitit.git
synced 2026-01-30 17:50:33 +00:00
Polish code
This commit is contained in:
parent
763440e41f
commit
2a08ba2c98
1 changed files with 12 additions and 13 deletions
|
|
@ -122,19 +122,18 @@
|
||||||
"
|
"
|
||||||
([] (redirect-trailing-slash-handler {:method :both}))
|
([] (redirect-trailing-slash-handler {:method :both}))
|
||||||
([{:keys [method]}]
|
([{:keys [method]}]
|
||||||
(let [redirect-handler (fn redirect-handler [request]
|
(letfn [(maybe-redirect [request path]
|
||||||
(let [uri (:uri request)
|
(if (r/match-by-path (::r/router request) path)
|
||||||
status (if (= (:request-method request) :get) 301 308)
|
{:status (if (= (:request-method request) :get) 301 308)
|
||||||
maybe-redirect (fn maybe-redirect [path]
|
:headers {"Location" path}
|
||||||
(if (r/match-by-path (::r/router request) path)
|
:body ""}))
|
||||||
{:status status
|
(redirect-handler [request]
|
||||||
:headers {"Location" path}
|
(let [uri (:uri request)]
|
||||||
:body ""}))]
|
(if (str/ends-with? uri "/")
|
||||||
(if (str/ends-with? uri "/")
|
(if (not= method :add)
|
||||||
(if (not= method :add)
|
(maybe-redirect request (subs uri 0 (-> uri count dec))))
|
||||||
(maybe-redirect (subs uri 0 (-> uri count dec))))
|
(if (not= method :strip)
|
||||||
(if (not= method :strip)
|
(maybe-redirect request (str uri "/"))))))]
|
||||||
(maybe-redirect (str uri "/"))))))]
|
|
||||||
(fn
|
(fn
|
||||||
([request]
|
([request]
|
||||||
(redirect-handler request))
|
(redirect-handler request))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue