diff --git a/src/frank/handler.cr b/src/frank/handler.cr index efe51bf..107d2a9 100644 --- a/src/frank/handler.cr +++ b/src/frank/handler.cr @@ -1,4 +1,4 @@ -require "net/http" +require "net/http/**" class Frank::Handler < HTTP::Handler INSTANCE = new @@ -21,14 +21,14 @@ class Frank::Handler < HTTP::Handler @routes.each do |route| params = route.match(request.method, components) if params - frank_request = Request.new(params) + frank_request = Request.new(request, params) context = Context.new(frank_request) 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", ex.to_s) end end end diff --git a/src/frank/request.cr b/src/frank/request.cr index 0150e69..55477bb 100644 --- a/src/frank/request.cr +++ b/src/frank/request.cr @@ -1,6 +1,8 @@ class Frank::Request getter params - def initialize(@params) + def initialize(@request, @params) end + + delegate body, @request end