kemal/src/kemal/context.cr

32 lines
639 B
Crystal
Raw Normal View History

# Context is the environment which holds request/response specific
# information such as params, content_type e.g
2015-10-23 18:33:26 +00:00
class Kemal::Context
getter request
2015-10-30 20:01:18 +00:00
getter response
2016-01-12 19:37:12 +00:00
getter route
2015-10-28 18:52:34 +00:00
getter content_type
2016-01-12 19:37:12 +00:00
def initialize(@request, @route)
2015-10-30 20:01:18 +00:00
@response = Kemal::Response.new
end
2015-10-30 20:01:18 +00:00
def response_headers
@response.headers
end
2015-10-30 20:34:44 +00:00
def add_header(name, value)
2015-10-30 20:01:18 +00:00
@response.headers.add name, value
end
def content_type
@response.content_type
2015-10-30 15:06:25 +00:00
end
2016-01-12 19:37:12 +00:00
def params
Kemal::ParamParser.new(@route, @request).parse
end
2015-10-30 20:34:44 +00:00
delegate headers, @request
2015-12-27 09:17:22 +00:00
delegate status_code, :"status_code=", :"content_type=", @response
end