Minor refactors

This commit is contained in:
Serdar Dogruyol 2017-12-08 21:35:02 +03:00
parent 8cb9770ec3
commit 56d34deef9
3 changed files with 6 additions and 3 deletions

View File

@ -1,11 +1,13 @@
module Kemal
module Utils
ZIP_TYPES = [".htm", ".html", ".txt", ".css", ".js", ".svg", ".json", ".xml", ".otf", ".ttf", ".woff", ".woff2"]
def self.path_starts_with_slash?(path : String)
path.starts_with?("/")
end
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
def self.mime_type(path : String)

View File

@ -6,6 +6,7 @@ module Kemal
URL_ENCODED_FORM = "application/x-www-form-urlencoded"
APPLICATION_JSON = "application/json"
MULTIPART_FORM = "multipart/form-data"
PARTS = %w(url query body json)
# :nodoc:
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Type) | Array(JSON::Type)
getter files
@ -28,7 +29,7 @@ module Kemal
value
end
{% for method in %w(url query body json) %}
{% for method in PARTS %}
def {{method.id}}
# check memoization
return @{{method.id}} if @{{method.id}}_parsed

View File

@ -20,7 +20,7 @@ module Kemal
# a corresponding `HEAD` route.
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("HEAD", path, Route.new("HEAD", path) { |ctx| "" }) if method == "GET"
add_to_radix_tree("HEAD", path, Route.new("HEAD", path) {}) if method == "GET"
end
# Check if a route is defined and returns the lookup