mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Minor refactors
This commit is contained in:
parent
8cb9770ec3
commit
56d34deef9
3 changed files with 6 additions and 3 deletions
|
@ -1,11 +1,13 @@
|
||||||
module Kemal
|
module Kemal
|
||||||
module Utils
|
module Utils
|
||||||
|
ZIP_TYPES = [".htm", ".html", ".txt", ".css", ".js", ".svg", ".json", ".xml", ".otf", ".ttf", ".woff", ".woff2"]
|
||||||
|
|
||||||
def self.path_starts_with_slash?(path : String)
|
def self.path_starts_with_slash?(path : String)
|
||||||
path.starts_with?("/")
|
path.starts_with?("/")
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.zip_types(path : String) # https://github.com/h5bp/server-configs-nginx/blob/master/nginx.conf
|
def self.zip_types(path : String) # https://github.com/h5bp/server-configs-nginx/blob/master/nginx.conf
|
||||||
[".htm", ".html", ".txt", ".css", ".js", ".svg", ".json", ".xml", ".otf", ".ttf", ".woff", ".woff2"].includes? File.extname(path)
|
ZIP_TYPES.includes? File.extname(path)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.mime_type(path : String)
|
def self.mime_type(path : String)
|
||||||
|
|
|
@ -6,6 +6,7 @@ module Kemal
|
||||||
URL_ENCODED_FORM = "application/x-www-form-urlencoded"
|
URL_ENCODED_FORM = "application/x-www-form-urlencoded"
|
||||||
APPLICATION_JSON = "application/json"
|
APPLICATION_JSON = "application/json"
|
||||||
MULTIPART_FORM = "multipart/form-data"
|
MULTIPART_FORM = "multipart/form-data"
|
||||||
|
PARTS = %w(url query body json)
|
||||||
# :nodoc:
|
# :nodoc:
|
||||||
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)
|
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)
|
||||||
getter files
|
getter files
|
||||||
|
@ -28,7 +29,7 @@ module Kemal
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
||||||
{% for method in %w(url query body json) %}
|
{% for method in PARTS %}
|
||||||
def {{method.id}}
|
def {{method.id}}
|
||||||
# check memoization
|
# check memoization
|
||||||
return @{{method.id}} if @{{method.id}}_parsed
|
return @{{method.id}} if @{{method.id}}_parsed
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Kemal
|
||||||
# a corresponding `HEAD` route.
|
# a corresponding `HEAD` route.
|
||||||
def add_route(method : String, path : String, &handler : HTTP::Server::Context -> _)
|
def add_route(method : String, path : String, &handler : HTTP::Server::Context -> _)
|
||||||
add_to_radix_tree method, path, Route.new(method, path, &handler)
|
add_to_radix_tree method, path, Route.new(method, path, &handler)
|
||||||
add_to_radix_tree("HEAD", path, Route.new("HEAD", path) { |ctx| "" }) if method == "GET"
|
add_to_radix_tree("HEAD", path, Route.new("HEAD", path) {}) if method == "GET"
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if a route is defined and returns the lookup
|
# Check if a route is defined and returns the lookup
|
||||||
|
|
Loading…
Reference in a new issue