mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Move redirect macro to context def
This commit is contained in:
parent
4dd027eb96
commit
17f944ef9d
4 changed files with 56 additions and 56 deletions
|
@ -196,15 +196,15 @@ describe "Kemal::Handler" do
|
||||||
client_response.status_code.should eq(404)
|
client_response.status_code.should eq(404)
|
||||||
end
|
end
|
||||||
|
|
||||||
# it "redirects user to provided url" do
|
it "redirects user to provided url" do
|
||||||
# kemal = Kemal::Handler.new
|
kemal = Kemal::Handler.new
|
||||||
# kemal.add_route "GET", "/" do |env|
|
kemal.add_route "GET", "/" do |env|
|
||||||
# redirect "/login"
|
env.redirect "/login"
|
||||||
# end
|
end
|
||||||
# request = HTTP::Request.new("GET", "/")
|
request = HTTP::Request.new("GET", "/")
|
||||||
# io_with_context = create_request_and_return_io(kemal, request)
|
io_with_context = create_request_and_return_io(kemal, request)
|
||||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
# client_response.status_code.should eq(301)
|
client_response.status_code.should eq(301)
|
||||||
# client_response.headers.has_key?("Location").should eq(true)
|
client_response.headers.has_key?("Location").should eq(true)
|
||||||
# end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# require "./spec_helper"
|
require "./spec_helper"
|
||||||
#
|
|
||||||
# macro render_with_base_and_layout(filename)
|
macro render_with_base_and_layout(filename)
|
||||||
# render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
|
render "spec/asset/#{{{filename}}}", "spec/asset/layout.ecr"
|
||||||
# end
|
end
|
||||||
#
|
|
||||||
# describe "Views" do
|
describe "Views" do
|
||||||
# it "renders file" do
|
# it "renders file" do
|
||||||
# kemal = Kemal::Handler.new
|
# kemal = Kemal::Handler.new
|
||||||
# kemal.add_route "GET", "/view/:name" do |env|
|
# kemal.add_route "GET", "/view/:name" do |env|
|
||||||
|
@ -15,7 +15,7 @@
|
||||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
# client_response.body.should contain("Hello world")
|
# client_response.body.should contain("Hello world")
|
||||||
# end
|
# end
|
||||||
#
|
|
||||||
# it "renders file with dynamic variables" do
|
# it "renders file with dynamic variables" do
|
||||||
# kemal = Kemal::Handler.new
|
# kemal = Kemal::Handler.new
|
||||||
# kemal.add_route "GET", "/view/:name" do |env|
|
# kemal.add_route "GET", "/view/:name" do |env|
|
||||||
|
@ -37,4 +37,4 @@
|
||||||
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
# client_response = HTTP::Client::Response.from_io(io_with_context, decompress: false)
|
||||||
# client_response.body.should contain("<html>Hello world")
|
# client_response.body.should contain("<html>Hello world")
|
||||||
# end
|
# end
|
||||||
# end
|
end
|
||||||
|
|
|
@ -7,5 +7,10 @@ class HTTP::Server
|
||||||
def params
|
def params
|
||||||
Kemal::ParamParser.new(@route, @request).parse
|
Kemal::ParamParser.new(@route, @request).parse
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def redirect(url)
|
||||||
|
@response.headers.add "Location", url
|
||||||
|
@response.status_code = 301
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,11 +16,6 @@ macro render(filename, layout)
|
||||||
render {{layout}}
|
render {{layout}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro redirect(url)
|
|
||||||
env.response.headers.add "Location", {{url}}
|
|
||||||
env.response.status_code = 301
|
|
||||||
end
|
|
||||||
|
|
||||||
macro add_handler(handler)
|
macro add_handler(handler)
|
||||||
Kemal.config.add_handler {{handler}}
|
Kemal.config.add_handler {{handler}}
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue