From 9607083e595e8eb4954fe3c3819694e913eeaf05 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Mon, 13 Feb 2017 23:39:40 +0300 Subject: [PATCH] Mark inner methods as private --- src/kemal/cli.cr | 6 +++--- src/kemal/common_exception_handler.cr | 2 +- src/kemal/param_parser.cr | 14 +++++++------- src/kemal/route_handler.cr | 2 +- src/kemal/static_file_handler.cr | 22 +++++++++++----------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/kemal/cli.cr b/src/kemal/cli.cr index 2b9e97d..86dd8cf 100644 --- a/src/kemal/cli.cr +++ b/src/kemal/cli.cr @@ -13,7 +13,7 @@ module Kemal configure_ssl end - def parse + private def parse OptionParser.parse! do |opts| opts.on("-b HOST", "--bind HOST", "Host to bind (defaults to 0.0.0.0)") do |host_binding| @config.host_binding = host_binding @@ -38,7 +38,7 @@ module Kemal end end - def configure_ssl + private def configure_ssl {% if !flag?(:without_openssl) %} if @ssl_enabled unless @key_file @@ -57,7 +57,7 @@ module Kemal {% end %} end - def read_env + private def read_env @config.env = ENV["KEMAL_ENV"] if ENV.has_key?("KEMAL_ENV") end end diff --git a/src/kemal/common_exception_handler.cr b/src/kemal/common_exception_handler.cr index 5682c54..184e1b1 100644 --- a/src/kemal/common_exception_handler.cr +++ b/src/kemal/common_exception_handler.cr @@ -19,7 +19,7 @@ module Kemal end end - def call_exception_with_status_code(context, exception, status_code) + private def call_exception_with_status_code(context, exception, status_code) if Kemal.config.error_handlers.has_key?(status_code) context.response.content_type = "text/html" unless context.response.headers.has_key?("Content-Type") context.response.print Kemal.config.error_handlers[status_code].call(context, exception) diff --git a/src/kemal/param_parser.cr b/src/kemal/param_parser.cr index dfb93e2..afa9e76 100644 --- a/src/kemal/param_parser.cr +++ b/src/kemal/param_parser.cr @@ -44,7 +44,7 @@ module Kemal end {% end %} - def parse_body + private def parse_body content_type = @request.headers["Content-Type"]? return unless content_type if content_type.try(&.starts_with?(URL_ENCODED_FORM)) @@ -57,11 +57,11 @@ module Kemal end end - def parse_query + private def parse_query @query = parse_part(@request.query) end - def parse_url + private def parse_url if params = @request.url_params params.each do |key, value| @url[key.as(String)] = unescape_url_param(value).as(String) @@ -69,7 +69,7 @@ module Kemal end end - def parse_file_upload + private def parse_file_upload HTTP::FormData.parse(@request) do |field, data, meta, headers| next unless meta filename = meta.filename @@ -89,7 +89,7 @@ module Kemal # If request body is a JSON Hash then all the params are parsed and added into `params`. # If request body is a JSON Array it's added into `params` as `_json` and can be accessed # like params["_json"] - def parse_json + private def parse_json return unless @request.body && @request.headers["Content-Type"]?.try(&.starts_with?(APPLICATION_JSON)) body = @request.body.not_nil!.gets_to_end @@ -103,7 +103,7 @@ module Kemal end end - def parse_part(part : IO?) + private def parse_part(part : IO?) if part HTTP::Params.parse(part.gets_to_end) else @@ -111,7 +111,7 @@ module Kemal end end - def parse_part(part : String?) + private def parse_part(part : String?) if part HTTP::Params.parse(part.to_s) else diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index 9031b41..e428179 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -30,7 +30,7 @@ module Kemal end # Processes the route if it's a match. Otherwise renders 404. - def process_request(context) + private def process_request(context) raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined? route = context.route_lookup.payload.as(Route) content = route.handler.call(context) diff --git a/src/kemal/static_file_handler.cr b/src/kemal/static_file_handler.cr index bd1b8df..3b7f033 100644 --- a/src/kemal/static_file_handler.cr +++ b/src/kemal/static_file_handler.cr @@ -79,7 +79,17 @@ module Kemal end end - def multipart(file, env) + def etag(context, file_path) + etag = %{W/"#{File.lstat(file_path).mtime.epoch.to_s}"} + context.response.headers["ETag"] = etag + return false if !context.request.headers["If-None-Match"]? || context.request.headers["If-None-Match"] != etag + context.response.headers.delete "Content-Type" + context.response.content_length = 0 + context.response.status_code = 304 # not modified + return true + end + + private def multipart(file, env) # See http://httpwg.org/specs/rfc7233.html fileb = file.size @@ -130,15 +140,5 @@ module Kemal IO.copy(file, env.response) end end - - def etag(context, file_path) - etag = %{W/"#{File.lstat(file_path).mtime.epoch.to_s}"} - context.response.headers["ETag"] = etag - return false if !context.request.headers["If-None-Match"]? || context.request.headers["If-None-Match"] != etag - context.response.headers.delete "Content-Type" - context.response.content_length = 0 - context.response.status_code = 304 # not modified - return true - end end end