Added context specs

This commit is contained in:
Sdogruyol 2015-10-28 20:52:34 +02:00
parent ad6baba12b
commit 5376eb8bb2
5 changed files with 36 additions and 27 deletions

View file

@ -1,15 +1,13 @@
class Kemal::Context
getter request
getter params
getter content_type
def initialize(@request, @params)
@content_type = "text/plain"
end
def response
@response ||= Response.new
end
def response?
@response
def set_content_type(content_type)
@content_type = content_type
end
end

View file

@ -26,7 +26,7 @@ class Kemal::Handler < HTTP::Handler
context = Context.new(request, params.not_nil!)
begin
body = route.handler.call(context).to_s
content_type = context.response?.try(&.content_type) || "text/plain"
content_type = context.content_type
return HTTP::Response.ok(content_type, body)
rescue ex
return HTTP::Response.error("text/plain", ex.to_s)