mirror of
https://github.com/metosin/reitit.git
synced 2025-12-21 18:11:12 +00:00
Merge pull request #164 from smahood/slash_handler_docs
Update docs for slash-handler
This commit is contained in:
commit
010211f7ec
1 changed files with 18 additions and 0 deletions
|
|
@ -66,3 +66,21 @@ Setting the `redirect-trailing-slash-handler` as a second argument to `ring-hand
|
||||||
(app {:uri "/pong"})
|
(app {:uri "/pong"})
|
||||||
; {:status 308, :headers {"Location" "/pong/"}, :body ""}
|
; {:status 308, :headers {"Location" "/pong/"}, :body ""}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
`redirect-trailing-slash-handler` can be composed with the default handler using `ring/routes` for more correct http error responses:
|
||||||
|
```clj
|
||||||
|
(def app
|
||||||
|
(ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
[["/ping" (constantly {:status 200, :body ""})]
|
||||||
|
["/pong/" (constantly {:status 200, :body ""})]])
|
||||||
|
(ring/routes
|
||||||
|
(ring/redirect-trailing-slash-handler {:method :add})
|
||||||
|
(ring/create-default-handler))))
|
||||||
|
|
||||||
|
(app {:uri "/ping/"})
|
||||||
|
; {:status 404, :body "", :headers {}}
|
||||||
|
|
||||||
|
(app {:uri "/pong"})
|
||||||
|
; {:status 308, :headers {"Location" "/pong/"}, :body ""}
|
||||||
|
```
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue