mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Merge pull request #32 from ilatif/master
Removed env from redirect and changed redirect from method to macro.
This commit is contained in:
commit
12c6af7d79
4 changed files with 7 additions and 7 deletions
|
@ -128,9 +128,10 @@ Just like other things in `kemal`, browser redirection is super simple as well.
|
|||
# Redirect browser
|
||||
get "/logout" do |env|
|
||||
# important stuff like clearing session etc.
|
||||
env.redirect "/login" # redirect to /login page
|
||||
redirect "/login" # redirect to /login page
|
||||
end
|
||||
```
|
||||
_Make sure to receive `env` as param in defined route's block or you might end-up having compile-time errors._
|
||||
|
||||
## Middlewares
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ describe "Kemal::Handler" do
|
|||
it "redirects user to provided url" do
|
||||
kemal = Kemal::Handler.new
|
||||
kemal.add_route "GET", "/" do |env|
|
||||
env.redirect("/login")
|
||||
redirect "/login"
|
||||
end
|
||||
request = HTTP::Request.new("GET", "/")
|
||||
response = kemal.call(request)
|
||||
|
|
|
@ -22,11 +22,6 @@ class Kemal::Context
|
|||
@response.content_type
|
||||
end
|
||||
|
||||
def redirect(url)
|
||||
@response.headers.add "Location", url
|
||||
@response.status_code = 301
|
||||
end
|
||||
|
||||
delegate headers, @request
|
||||
delegate status_code, @response
|
||||
delegate :"status_code=", @response
|
||||
|
|
4
src/kemal/macros.cr
Normal file
4
src/kemal/macros.cr
Normal file
|
@ -0,0 +1,4 @@
|
|||
macro redirect(url)
|
||||
env.response.headers.add "Location", {{url}}
|
||||
env.response.status_code = 301
|
||||
end
|
Loading…
Reference in a new issue