Compare commits
4 commits
2077cfb8b9
...
3c2dcc73e5
Author | SHA1 | Date | |
---|---|---|---|
3c2dcc73e5 | |||
|
70684a2cf0 | ||
|
c3c43145b8 | ||
|
b7506f6fab |
4 changed files with 18 additions and 1 deletions
|
@ -118,6 +118,18 @@ describe "Kemal::RouteHandler" do
|
||||||
request = HTTP::Request.new("GET", "/")
|
request = HTTP::Request.new("GET", "/")
|
||||||
client_response = call_request_on_app(request)
|
client_response = call_request_on_app(request)
|
||||||
client_response.status_code.should eq(302)
|
client_response.status_code.should eq(302)
|
||||||
|
client_response.body.should eq("")
|
||||||
|
client_response.headers.has_key?("Location").should eq(true)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "redirects with body" do
|
||||||
|
get "/" do |env|
|
||||||
|
env.redirect "/login", body: "Redirecting to /login"
|
||||||
|
end
|
||||||
|
request = HTTP::Request.new("GET", "/")
|
||||||
|
client_response = call_request_on_app(request)
|
||||||
|
client_response.status_code.should eq(302)
|
||||||
|
client_response.body.should eq("Redirecting to /login")
|
||||||
client_response.headers.has_key?("Location").should eq(true)
|
client_response.headers.has_key?("Location").should eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -17,9 +17,10 @@ class HTTP::Server
|
||||||
@params ||= Kemal::ParamParser.new(@request, route_lookup.params)
|
@params ||= Kemal::ParamParser.new(@request, route_lookup.params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def redirect(url : String, status_code : Int32 = 302)
|
def redirect(url : String, status_code : Int32 = 302, *, body : String? = nil)
|
||||||
@response.headers.add "Location", url
|
@response.headers.add "Location", url
|
||||||
@response.status_code = status_code
|
@response.status_code = status_code
|
||||||
|
@response.print(body) if body
|
||||||
end
|
end
|
||||||
|
|
||||||
def route
|
def route
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
require "flate"
|
||||||
|
require "gzip"
|
||||||
require "mime"
|
require "mime"
|
||||||
|
|
||||||
# Adds given `Kemal::Handler` to handlers chain.
|
# Adds given `Kemal::Handler` to handlers chain.
|
||||||
|
|
|
@ -97,6 +97,8 @@ module Kemal
|
||||||
end
|
end
|
||||||
when Array
|
when Array
|
||||||
@json["_json"] = json
|
@json["_json"] = json
|
||||||
|
else
|
||||||
|
# Ignore non Array or Hash json values
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue