Compare commits
8 Commits
c995a2a971
...
7c47bbc150
Author | SHA1 | Date |
---|---|---|
Sijawusz Pur Rahnama | 7c47bbc150 | |
Serdar Dogruyol | bef7351000 | |
Serdar Dogruyol - Sedo セド | bb9105f202 | |
Sijawusz Pur Rahnama | 9628043e4c | |
Giorgi Kavrelishvili | 0de0e990e9 | |
Val Packett | 13fd4f8b2f | |
Thomas Fini Hansen | cb9adcd188 | |
Giorgi Kavrelishvili | a939a577de |
|
@ -10,12 +10,11 @@ dependencies:
|
|||
version: ~> 0.4.0
|
||||
exception_page:
|
||||
github: crystal-loot/exception_page
|
||||
version: ~> 0.3.0
|
||||
version: ~> 0.4.1
|
||||
|
||||
development_dependencies:
|
||||
ameba:
|
||||
github: crystal-ameba/ameba
|
||||
version: ~> 1.4.0
|
||||
|
||||
crystal: ">= 0.36.0"
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ describe "Kemal::WebSocketHandler" do
|
|||
|
||||
it "fetches named url parameters" do
|
||||
handler = Kemal::WebSocketHandler::INSTANCE
|
||||
ws "/:id" { |_, c| c.ws_route_lookup.params["id"] }
|
||||
ws "/:id" { |_, context| context.ws_route_lookup.params["id"] }
|
||||
headers = HTTP::Headers{
|
||||
"Upgrade" => "websocket",
|
||||
"Connection" => "Upgrade",
|
||||
|
|
|
@ -89,7 +89,7 @@ module Kemal
|
|||
end
|
||||
|
||||
private def self.setup_trap_signal
|
||||
Signal::INT.trap do
|
||||
Process.on_interrupt do
|
||||
log "#{Kemal.config.app_name} is going to take a rest!" if Kemal.config.shutdown_message
|
||||
Kemal.stop
|
||||
exit
|
||||
|
|
|
@ -159,8 +159,8 @@ module Kemal
|
|||
end
|
||||
|
||||
private def setup_filter_handlers
|
||||
FILTER_HANDLERS.each do |h|
|
||||
HANDLERS.insert(@handler_position, h)
|
||||
FILTER_HANDLERS.each do |handler|
|
||||
HANDLERS.insert(@handler_position, handler)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ class HTTP::Server
|
|||
STORE_MAPPINGS = [Nil, String, Int32, Int64, Float64, Bool]
|
||||
|
||||
macro finished
|
||||
alias StoreTypes = Union({{ *STORE_MAPPINGS }})
|
||||
alias StoreTypes = Union({{ STORE_MAPPINGS.splat }})
|
||||
@store = {} of String => StoreTypes
|
||||
end
|
||||
|
||||
|
@ -17,8 +17,8 @@ class HTTP::Server
|
|||
@params ||= Kemal::ParamParser.new(@request, route_lookup.params)
|
||||
end
|
||||
|
||||
def redirect(url : String, status_code : Int32 = 302, *, body : String? = nil, close : Bool = true)
|
||||
@response.headers.add "Location", url
|
||||
def redirect(url : String | URI, status_code : Int32 = 302, *, body : String? = nil, close : Bool = true)
|
||||
@response.headers.add "Location", url.to_s
|
||||
@response.status_code = status_code
|
||||
@response.print(body) if body
|
||||
@response.close if close
|
||||
|
|
|
@ -13,8 +13,9 @@ module Kemal::Exceptions
|
|||
end
|
||||
|
||||
class CustomException < Exception
|
||||
def initialize(context : HTTP::Server::Context)
|
||||
super "Rendered error with #{context.response.status_code}"
|
||||
def initialize(@context : HTTP::Server::Context, message : String? = nil)
|
||||
message ||= "Rendered error with #{context.response.status_code}"
|
||||
super message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 && !flag?(:without_zlib) %}
|
||||
require "compress/deflate"
|
||||
require "compress/gzip"
|
||||
{% end %}
|
||||
|
@ -141,33 +141,38 @@ def send_file(env : HTTP::Server::Context, path : String, mime_type : String? =
|
|||
next multipart(file, env)
|
||||
end
|
||||
|
||||
condition = config.is_a?(Hash) && config["gzip"]? == true && filesize > minsize && Kemal::Utils.zip_types(file_path)
|
||||
if condition && request_headers.includes_word?("Accept-Encoding", "gzip")
|
||||
env.response.headers["Content-Encoding"] = "gzip"
|
||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
||||
Compress::Gzip::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% else %}
|
||||
Gzip::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% end %}
|
||||
elsif condition && request_headers.includes_word?("Accept-Encoding", "deflate")
|
||||
env.response.headers["Content-Encoding"] = "deflate"
|
||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
||||
Compress::Deflate::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% else %}
|
||||
Flate::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% end %}
|
||||
else
|
||||
{% if flag?(:without_zlib) %}
|
||||
env.response.content_length = filesize
|
||||
IO.copy(file, env.response)
|
||||
end
|
||||
{% else %}
|
||||
condition = config.is_a?(Hash) && config["gzip"]? == true && filesize > minsize && Kemal::Utils.zip_types(file_path)
|
||||
if condition && request_headers.includes_word?("Accept-Encoding", "gzip")
|
||||
env.response.headers["Content-Encoding"] = "gzip"
|
||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
||||
Compress::Gzip::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% else %}
|
||||
Gzip::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% end %}
|
||||
elsif condition && request_headers.includes_word?("Accept-Encoding", "deflate")
|
||||
env.response.headers["Content-Encoding"] = "deflate"
|
||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
||||
Compress::Deflate::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% else %}
|
||||
Flate::Writer.open(env.response) do |deflate|
|
||||
IO.copy(file, deflate)
|
||||
end
|
||||
{% end %}
|
||||
else
|
||||
env.response.content_length = filesize
|
||||
IO.copy(file, env.response)
|
||||
end
|
||||
{% end %}
|
||||
end
|
||||
return
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue