From 56d34deef97dfef9f4534ec58aeca54a8fa8694b Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Fri, 8 Dec 2017 21:35:02 +0300 Subject: [PATCH] Minor refactors --- src/kemal/helpers/utils.cr | 4 +++- src/kemal/param_parser.cr | 3 ++- src/kemal/route_handler.cr | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/kemal/helpers/utils.cr b/src/kemal/helpers/utils.cr index b0e0253..30a0d58 100644 --- a/src/kemal/helpers/utils.cr +++ b/src/kemal/helpers/utils.cr @@ -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) diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index 01cb8c5..1545e2b 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -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 diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index 3860073..fedfacc 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -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