Crystal 0.25.0 (#452)

This commit is contained in:
Serdar Dogruyol 2018-06-16 18:03:00 +03:00 committed by GitHub
parent c2236acf3a
commit a5870e7d24
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 23 additions and 22 deletions

View file

@ -59,7 +59,7 @@ module Kemal
end
end
config.server ||= HTTP::Server.new(config.host_binding, config.port, config.handlers)
server = config.server ||= HTTP::Server.new(config.handlers)
{% if !flag?(:without_openssl) %}
config.server.not_nil!.tls = config.ssl
@ -68,13 +68,13 @@ module Kemal
config.running = true
yield config
config.server.not_nil!.listen if config.env != "test" && config.server
server.listen(config.host_binding, config.port) if config.env != "test"
end
def self.stop
if config.running
if config.server
config.server.not_nil!.close
if server = config.server
server.close unless server.closed?
config.running = false
else
raise "Kemal.config.server is not set. Please use Kemal.run to set the server."

View file

@ -21,7 +21,7 @@ module Kemal
property host_binding, ssl, port, env, public_folder, logging, running
property always_rescue, server : HTTP::Server?, extra_options, shutdown_message
property serve_static : (Bool | Hash(String, Bool))
property static_headers : (HTTP::Server::Response, String, File::Stat -> Void)?
property static_headers : (HTTP::Server::Response, String, File::Info -> Void)?
property powered_by_header : Bool = true
def initialize

View file

@ -119,7 +119,7 @@ def send_file(env : HTTP::Server::Context, path : String, mime_type : String? =
minsize = 860 # http://webmasters.stackexchange.com/questions/31750/what-is-recommended-minimum-object-size-for-gzip-performance-benefits ??
request_headers = env.request.headers
filesize = File.size(file_path)
filestat = File.stat(file_path)
filestat = File.info(file_path)
Kemal.config.static_headers.try(&.call(env.response, file_path, filestat))
@ -234,6 +234,6 @@ end
# response.headers.add("Content-Size", filestat.size.to_s)
# end
# ```
def static_headers(&headers : HTTP::Server::Response, String, File::Stat -> Void)
def static_headers(&headers : HTTP::Server::Response, String, File::Info -> Void)
Kemal.config.static_headers = headers
end

View file

@ -8,7 +8,7 @@ module Kemal
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)
alias AllParamTypes = Nil | String | Int64 | Float64 | Bool | Hash(String, JSON::Any) | Array(JSON::Any)
getter files
def initialize(@request : HTTP::Request)
@ -89,7 +89,7 @@ module Kemal
case json = JSON.parse(body).raw
when Hash
json.each do |key, value|
@json[key] = value.as(AllParamTypes)
@json[key] = value.raw
end
when Array
@json["_json"] = json

View file

@ -58,7 +58,7 @@ module Kemal
end
private def etag(context : HTTP::Server::Context, file_path : String)
etag = %{W/"#{File.lstat(file_path).mtime.epoch.to_s}"}
etag = %{W/"#{File.info(file_path).modification_time.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"