only return strings from routes fixes #374 (#408)

This commit is contained in:
Cris Ward 2017-10-02 21:47:43 +01:00 committed by Serdar Dogruyol
parent 8cf3f67594
commit 30bdcc9759
2 changed files with 12 additions and 1 deletions

View File

@ -10,6 +10,15 @@ describe "Kemal::RouteHandler" do
client_response.body.should eq("hello")
end
it "routes should only return strings" do
get "/" do
100
end
request = HTTP::Request.new("GET", "/")
client_response = call_request_on_app(request)
client_response.body.should eq("")
end
it "routes request with query string" do
get "/" do |env|
"hello #{env.params.query["message"]}"
@ -155,4 +164,5 @@ describe "Kemal::RouteHandler" do
client_response.status_code.should eq(302)
client_response.headers.has_key?("Location").should eq(true)
end
end

View File

@ -8,7 +8,8 @@ module Kemal
def initialize(@method : String, @path : String, &handler : HTTP::Server::Context -> _)
@handler = ->(context : HTTP::Server::Context) do
handler.call(context).to_s
output = handler.call(context)
output.is_a?(String) ? output : ""
end
end
end