mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Format
This commit is contained in:
parent
e9665c124b
commit
f92d812c32
6 changed files with 9 additions and 11 deletions
|
@ -3,7 +3,6 @@ require "option_parser"
|
|||
module Kemal
|
||||
# Handles all the initialization from the command line.
|
||||
class CLI
|
||||
|
||||
def initialize
|
||||
@ssl_enabled = false
|
||||
@key_file = ""
|
||||
|
|
|
@ -13,7 +13,7 @@ class HTTP::Server
|
|||
end
|
||||
|
||||
def route_lookup
|
||||
Kemal::RouteHandler::INSTANCE.lookup_route(@request.override_method as String, @request.path)
|
||||
Kemal::RouteHandler::INSTANCE.lookup_route(@request.override_method.as(String), @request.path)
|
||||
end
|
||||
|
||||
def route_defined?
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
module Kemal::Exceptions
|
||||
class RouteNotFound < Exception
|
||||
def initialize(context)
|
||||
super "Requested path: '#{context.request.override_method as String}:#{context.request.path}' was not found."
|
||||
super "Requested path: '#{context.request.override_method.as(String)}:#{context.request.path}' was not found."
|
||||
end
|
||||
end
|
||||
|
||||
class CustomException < Exception
|
||||
|
||||
def initialize(context)
|
||||
super "Rendered error with #{context.response.status_code}"
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module Kemal::Middleware
|
|||
def _add_route_filter(verb, path, type, &block : HTTP::Server::Context -> _)
|
||||
lookup = lookup_filters_for_path_type(verb, path, type)
|
||||
if lookup.found? && lookup.payload.is_a?(Array(Block))
|
||||
(lookup.payload as Array(Block)) << Block.new(&block)
|
||||
(lookup.payload.as(Array(Block))) << Block.new(&block)
|
||||
else
|
||||
@tree.add radix_path(verb, path, type), [Block.new(&block)]
|
||||
end
|
||||
|
@ -49,7 +49,7 @@ module Kemal::Middleware
|
|||
private def call_block_for_path_type(verb, path, type, context)
|
||||
lookup = lookup_filters_for_path_type(verb, path, type)
|
||||
if lookup.found? && lookup.payload.is_a? Array(Block)
|
||||
blocks = lookup.payload as Array(Block)
|
||||
blocks = lookup.payload.as(Array(Block))
|
||||
blocks.each { |block| block.call(context) }
|
||||
end
|
||||
end
|
||||
|
@ -74,7 +74,7 @@ module Kemal::Middleware
|
|||
property block : HTTP::Server::Context -> String
|
||||
|
||||
def initialize(&block : HTTP::Server::Context -> _)
|
||||
@block = ->(context : HTTP::Server::Context) { block.call(context).to_s}
|
||||
@block = ->(context : HTTP::Server::Context) { block.call(context).to_s }
|
||||
end
|
||||
|
||||
def call(context)
|
||||
|
|
|
@ -44,7 +44,7 @@ class Kemal::ParamParser
|
|||
def parse_url
|
||||
if params = @request.url_params
|
||||
params.each do |key, value|
|
||||
@url[key as String] = value as String
|
||||
@url[key.as(String)] = value.as(String)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -56,11 +56,11 @@ class Kemal::ParamParser
|
|||
def parse_json
|
||||
return unless @request.body && @request.headers["Content-Type"]? == APPLICATION_JSON
|
||||
|
||||
body = @request.body as String
|
||||
body = @request.body.as(String)
|
||||
case json = JSON.parse(body).raw
|
||||
when Hash
|
||||
json.each do |key, value|
|
||||
@json[key as String] = value as AllParamTypes
|
||||
@json[key.as(String)] = value.as(AllParamTypes)
|
||||
end
|
||||
when Array
|
||||
@json["_json"] = json
|
||||
|
|
|
@ -32,7 +32,7 @@ class Kemal::RouteHandler < HTTP::Handler
|
|||
# Processes the route if it's a match. Otherwise renders 404.
|
||||
def process_request(context)
|
||||
raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined?
|
||||
route = context.route_lookup.payload as Route
|
||||
route = context.route_lookup.payload.as(Route)
|
||||
content = route.handler.call(context)
|
||||
if Kemal.config.error_handlers.has_key?(context.response.status_code)
|
||||
raise Kemal::Exceptions::CustomException.new(context)
|
||||
|
|
Loading…
Reference in a new issue