mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Added context specs
This commit is contained in:
parent
ad6baba12b
commit
5376eb8bb2
5 changed files with 36 additions and 27 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue