mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Updating to instance types
This commit is contained in:
parent
de98236fc4
commit
05e44e68c6
15 changed files with 27 additions and 18 deletions
|
@ -155,5 +155,4 @@ describe "Kemal::RouteHandler" do
|
|||
client_response.status_code.should eq(302)
|
||||
client_response.headers.has_key?("Location").should eq(true)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -53,5 +53,5 @@ end
|
|||
|
||||
Spec.after_each do
|
||||
Kemal.config.handlers.clear
|
||||
Kemal::RouteHandler::INSTANCE.tree = Radix::Tree.new
|
||||
Kemal::RouteHandler::INSTANCE.tree = Radix::Tree(Route).new
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require "http"
|
||||
|
||||
class Kemal::BaseLogHandler < HTTP::Handler
|
||||
def initialize(@env)
|
||||
def initialize(@env : String)
|
||||
end
|
||||
|
||||
def call(context)
|
||||
|
|
|
@ -2,10 +2,13 @@ require "option_parser"
|
|||
|
||||
module Kemal
|
||||
class CLI
|
||||
@config : Kemal::Config
|
||||
@key_file : String
|
||||
|
||||
def initialize
|
||||
@ssl_enabled = false
|
||||
@key_file = nil
|
||||
@cert_file = nil
|
||||
@key_file = ""
|
||||
@cert_file = ""
|
||||
@config = Kemal.config
|
||||
parse
|
||||
configure_ssl
|
||||
|
|
|
@ -2,6 +2,7 @@ require "colorize"
|
|||
require "http"
|
||||
|
||||
class Kemal::CommonLogHandler < Kemal::BaseLogHandler
|
||||
@handler : IO::FileDescriptor+
|
||||
getter handler
|
||||
|
||||
def initialize(@env)
|
||||
|
|
|
@ -2,6 +2,8 @@ module Kemal
|
|||
class Config
|
||||
INSTANCE = Config.new
|
||||
HANDLERS = [] of HTTP::Handler
|
||||
@ssl : OpenSSL::SSL::Context
|
||||
|
||||
property host_binding, ssl, port, env, public_folder, logging,
|
||||
always_rescue, error_handler, serve_static, run
|
||||
|
||||
|
@ -14,8 +16,9 @@ module Kemal
|
|||
@logging = true
|
||||
@logger = nil
|
||||
@always_rescue = true
|
||||
@error_handler = nil
|
||||
@error_handler = uninitialized Kemal::CommonExceptionHandler
|
||||
@run = false
|
||||
@ssl = uninitialized OpenSSL::SSL::Context
|
||||
end
|
||||
|
||||
def logger
|
||||
|
|
|
@ -13,7 +13,7 @@ class HTTP::Server
|
|||
end
|
||||
|
||||
def route_lookup
|
||||
@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?
|
||||
|
|
|
@ -52,7 +52,6 @@ def logger(logger)
|
|||
Kemal.config.add_handler logger
|
||||
end
|
||||
|
||||
|
||||
def serve_static(status)
|
||||
Kemal.config.serve_static = status
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Kemal::Middleware
|
|||
|
||||
# This middleware is lazily instantiated and added to the handlers as soon as a call to `after_X` or `before_X` is made.
|
||||
def initialize
|
||||
@tree = Radix::Tree.new
|
||||
@tree = Radix::Tree(Array(Kemal::Middleware::Block)).new
|
||||
Kemal.config.add_handler(self)
|
||||
end
|
||||
|
||||
|
@ -68,7 +68,7 @@ module Kemal::Middleware
|
|||
end
|
||||
|
||||
class Block
|
||||
property block
|
||||
property block : (HTTP::Server::Context -> )
|
||||
|
||||
def initialize(&@block : HTTP::Server::Context -> _)
|
||||
end
|
||||
|
|
|
@ -13,7 +13,7 @@ module Kemal::Middleware
|
|||
AUTH_MESSAGE = "Could not verify your access level for that URL.\nYou have to login with proper credentials"
|
||||
HEADER_LOGIN_REQUIRED = "Basic realm=\"Login Required\""
|
||||
|
||||
def initialize(@username, @password)
|
||||
def initialize(@username : String?, @password : String?)
|
||||
end
|
||||
|
||||
def call(context)
|
||||
|
|
|
@ -9,11 +9,15 @@ class Kemal::ParamParser
|
|||
URL_ENCODED_FORM = "application/x-www-form-urlencoded"
|
||||
APPLICATION_JSON = "application/json"
|
||||
|
||||
def initialize(@request)
|
||||
def initialize(@request : HTTP::Request, @url_params : String? = nil , @override_method : String? = nil)
|
||||
@url = {} of String => String
|
||||
@query = {} of String => String
|
||||
@body = {} of String => String
|
||||
@json = {} of String => AllParamTypes
|
||||
@url_parsed = false
|
||||
@query_parsed = false
|
||||
@body_parsed = false
|
||||
@json_parsed = false
|
||||
end
|
||||
|
||||
{% for method in %w(url query body json) %}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Opening HTTP::Request to add override_method property
|
||||
class HTTP::Request
|
||||
property override_method
|
||||
property url_params
|
||||
property url_params : Hash(String, String)?
|
||||
|
||||
def override_method
|
||||
@override_method ||= check_for_method_override!
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
# It takes 3 parameters: Method, path and a block to specify
|
||||
# what action to be done if the route is matched.
|
||||
class Kemal::Route
|
||||
getter handler
|
||||
getter handler : (HTTP::Server::Context -> )
|
||||
getter method
|
||||
|
||||
def initialize(@method, @path, &@handler : HTTP::Server::Context -> _)
|
||||
def initialize(@method : String, @path : String, &@handler : HTTP::Server::Context -> )
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class Kemal::RouteHandler < HTTP::Handler
|
|||
property tree
|
||||
|
||||
def initialize
|
||||
@tree = Radix::Tree.new
|
||||
@tree = Radix::Tree(Route).new
|
||||
end
|
||||
|
||||
def call(context)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# Kemal::WebSocketHandler is used for each define WebSocket route.
|
||||
# For each WebSocket route a new handler is created and registered to global handlers.
|
||||
class Kemal::WebSocketHandler < HTTP::WebSocketHandler
|
||||
def initialize(@path, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)
|
||||
def initialize(@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Void)
|
||||
Kemal.config.add_ws_handler self
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue