2015-10-29 15:16:29 +00:00
|
|
|
# Context is the environment which holds request/response specific
|
|
|
|
# information such as params, content_type e.g
|
2016-01-24 10:22:25 +00:00
|
|
|
class HTTP::Server
|
|
|
|
class Context
|
|
|
|
def params
|
2016-05-21 12:00:44 +00:00
|
|
|
@request.url_params ||= route_lookup.params
|
2016-03-06 19:43:13 +00:00
|
|
|
@params ||= Kemal::ParamParser.new(@request)
|
2016-01-24 10:22:25 +00:00
|
|
|
end
|
2016-01-24 10:52:41 +00:00
|
|
|
|
2016-02-09 15:25:01 +00:00
|
|
|
def redirect(url, status_code = 302)
|
2016-01-24 10:52:41 +00:00
|
|
|
@response.headers.add "Location", url
|
2016-02-09 15:25:01 +00:00
|
|
|
@response.status_code = status_code
|
2016-01-24 10:52:41 +00:00
|
|
|
end
|
2016-02-16 20:07:58 +00:00
|
|
|
|
|
|
|
def route_lookup
|
2016-06-15 05:58:14 +00:00
|
|
|
Kemal::RouteHandler::INSTANCE.lookup_route(@request.override_method.as(String), @request.path)
|
2016-02-16 20:07:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def route_defined?
|
|
|
|
route_lookup.found?
|
|
|
|
end
|
2016-06-27 21:37:40 +00:00
|
|
|
|
|
|
|
def session
|
|
|
|
@session ||= Kemal::Sessions.new(self)
|
|
|
|
@session.not_nil!
|
|
|
|
end
|
2014-07-30 23:50:14 +00:00
|
|
|
end
|
|
|
|
end
|