Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match HTTP::Response params and return the output of the route #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/frank/handler.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ class Frank::Handler < HTTP::Handler
begin
body = route.handler.call(context).to_s
content_type = context.response?.try(&.content_type) || "text/plain"
return HTTP::Response.new("HTTP/1.1", 200, "OK", {"Content-Type" => content_type}, body)
return HTTP::Response.ok(content_type, body)
rescue ex
return HTTP::Response.new("HTTP/1.1", 500, "Internal Server Error", {"Content-Type" => "text/plain"}, ex.to_s)
return HTTP::Response.error("text/plain", "Internal Server Error:\n #{ex.to_s}")
end
else
return HTTP::Response.not_found
end
end
nil
Expand Down