Mark inner methods as private
This commit is contained in:
parent
c6ff2c5d2e
commit
9607083e59
5 changed files with 23 additions and 23 deletions
|
@ -13,7 +13,7 @@ module Kemal
|
||||||
configure_ssl
|
configure_ssl
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse
|
private def parse
|
||||||
OptionParser.parse! do |opts|
|
OptionParser.parse! do |opts|
|
||||||
opts.on("-b HOST", "--bind HOST", "Host to bind (defaults to 0.0.0.0)") do |host_binding|
|
opts.on("-b HOST", "--bind HOST", "Host to bind (defaults to 0.0.0.0)") do |host_binding|
|
||||||
@config.host_binding = host_binding
|
@config.host_binding = host_binding
|
||||||
|
@ -38,7 +38,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def configure_ssl
|
private def configure_ssl
|
||||||
{% if !flag?(:without_openssl) %}
|
{% if !flag?(:without_openssl) %}
|
||||||
if @ssl_enabled
|
if @ssl_enabled
|
||||||
unless @key_file
|
unless @key_file
|
||||||
|
@ -57,7 +57,7 @@ module Kemal
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_env
|
private def read_env
|
||||||
@config.env = ENV["KEMAL_ENV"] if ENV.has_key?("KEMAL_ENV")
|
@config.env = ENV["KEMAL_ENV"] if ENV.has_key?("KEMAL_ENV")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
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)
|
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.content_type = "text/html" unless context.response.headers.has_key?("Content-Type")
|
||||||
context.response.print Kemal.config.error_handlers[status_code].call(context, exception)
|
context.response.print Kemal.config.error_handlers[status_code].call(context, exception)
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
def parse_body
|
private def parse_body
|
||||||
content_type = @request.headers["Content-Type"]?
|
content_type = @request.headers["Content-Type"]?
|
||||||
return unless content_type
|
return unless content_type
|
||||||
if content_type.try(&.starts_with?(URL_ENCODED_FORM))
|
if content_type.try(&.starts_with?(URL_ENCODED_FORM))
|
||||||
|
@ -57,11 +57,11 @@ module Kemal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_query
|
private def parse_query
|
||||||
@query = parse_part(@request.query)
|
@query = parse_part(@request.query)
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_url
|
private def parse_url
|
||||||
if params = @request.url_params
|
if params = @request.url_params
|
||||||
params.each do |key, value|
|
params.each do |key, value|
|
||||||
@url[key.as(String)] = unescape_url_param(value).as(String)
|
@url[key.as(String)] = unescape_url_param(value).as(String)
|
||||||
|
@ -69,7 +69,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_file_upload
|
private def parse_file_upload
|
||||||
HTTP::FormData.parse(@request) do |field, data, meta, headers|
|
HTTP::FormData.parse(@request) do |field, data, meta, headers|
|
||||||
next unless meta
|
next unless meta
|
||||||
filename = meta.filename
|
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 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
|
# If request body is a JSON Array it's added into `params` as `_json` and can be accessed
|
||||||
# like params["_json"]
|
# like params["_json"]
|
||||||
def parse_json
|
private def parse_json
|
||||||
return unless @request.body && @request.headers["Content-Type"]?.try(&.starts_with?(APPLICATION_JSON))
|
return unless @request.body && @request.headers["Content-Type"]?.try(&.starts_with?(APPLICATION_JSON))
|
||||||
|
|
||||||
body = @request.body.not_nil!.gets_to_end
|
body = @request.body.not_nil!.gets_to_end
|
||||||
|
@ -103,7 +103,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_part(part : IO?)
|
private def parse_part(part : IO?)
|
||||||
if part
|
if part
|
||||||
HTTP::Params.parse(part.gets_to_end)
|
HTTP::Params.parse(part.gets_to_end)
|
||||||
else
|
else
|
||||||
|
@ -111,7 +111,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_part(part : String?)
|
private def parse_part(part : String?)
|
||||||
if part
|
if part
|
||||||
HTTP::Params.parse(part.to_s)
|
HTTP::Params.parse(part.to_s)
|
||||||
else
|
else
|
||||||
|
|
|
@ -30,7 +30,7 @@ module Kemal
|
||||||
end
|
end
|
||||||
|
|
||||||
# Processes the route if it's a match. Otherwise renders 404.
|
# 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?
|
raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined?
|
||||||
route = context.route_lookup.payload.as(Route)
|
route = context.route_lookup.payload.as(Route)
|
||||||
content = route.handler.call(context)
|
content = route.handler.call(context)
|
||||||
|
|
|
@ -79,7 +79,17 @@ module Kemal
|
||||||
end
|
end
|
||||||
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
|
# See http://httpwg.org/specs/rfc7233.html
|
||||||
fileb = file.size
|
fileb = file.size
|
||||||
|
|
||||||
|
@ -130,15 +140,5 @@ module Kemal
|
||||||
IO.copy(file, env.response)
|
IO.copy(file, env.response)
|
||||||
end
|
end
|
||||||
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
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue