Compare commits
No commits in common. "c3cd44205f6132aa1e9a38046da267328cb009da" and "3c2dcc73e538f0bf8e935062055688429626ab3a" have entirely different histories.
c3cd44205f
...
3c2dcc73e5
8 changed files with 23 additions and 45 deletions
|
@ -18,7 +18,7 @@ dependencies:
|
||||||
development_dependencies:
|
development_dependencies:
|
||||||
ameba:
|
ameba:
|
||||||
github: crystal-ameba/ameba
|
github: crystal-ameba/ameba
|
||||||
version: ~> 0.12.0
|
version: ~> 0.10.0
|
||||||
|
|
||||||
crystal: 0.30.0
|
crystal: 0.30.0
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,6 @@ describe "Kemal::RouteHandler" do
|
||||||
client_response.body.should eq("hello")
|
client_response.body.should eq("hello")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "routes with long response body" do
|
|
||||||
long_response_body = "string" * 10_000
|
|
||||||
|
|
||||||
get "/" do
|
|
||||||
long_response_body
|
|
||||||
end
|
|
||||||
request = HTTP::Request.new("GET", "/")
|
|
||||||
client_response = call_request_on_app(request)
|
|
||||||
client_response.body.should eq(long_response_body)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "routes should only return strings" do
|
it "routes should only return strings" do
|
||||||
get "/" do
|
get "/" do
|
||||||
100
|
100
|
||||||
|
|
|
@ -5,12 +5,12 @@ private def run(code)
|
||||||
require "./src/kemal"
|
require "./src/kemal"
|
||||||
#{code}
|
#{code}
|
||||||
CR
|
CR
|
||||||
|
String.build do |stdout|
|
||||||
stdout = IO::Memory.new
|
stderr = String.build do |io|
|
||||||
stderr = IO::Memory.new
|
Process.new("crystal", ["eval"], input: IO::Memory.new(code), output: stdout, error: io).wait
|
||||||
status = Process.new("crystal", ["eval"], input: IO::Memory.new(code), output: stdout, error: stderr).wait
|
end
|
||||||
fail(stderr.to_s) unless status.success?
|
fail(stderr) unless stderr.empty?
|
||||||
stdout.to_s
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "Run" do
|
describe "Run" do
|
||||||
|
|
|
@ -48,9 +48,6 @@ def create_ws_request_and_return_io_and_context(handler, request)
|
||||||
rescue IO::Error
|
rescue IO::Error
|
||||||
# Raises because the IO::Memory is empty
|
# Raises because the IO::Memory is empty
|
||||||
end
|
end
|
||||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
|
||||||
response.upgrade_handler.try &.call(io)
|
|
||||||
{% end %}
|
|
||||||
io.rewind
|
io.rewind
|
||||||
{io, context}
|
{io, context}
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,7 +8,7 @@ class HTTP::Server::Response
|
||||||
|
|
||||||
ensure_headers_written
|
ensure_headers_written
|
||||||
|
|
||||||
previous_def
|
super
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
{% if compare_versions(Crystal::VERSION, "0.35.0-0") >= 0 %}
|
require "flate"
|
||||||
require "compress/deflate"
|
require "gzip"
|
||||||
require "compress/gzip"
|
|
||||||
{% end %}
|
|
||||||
require "mime"
|
require "mime"
|
||||||
|
|
||||||
# Adds given `Kemal::Handler` to handlers chain.
|
# Adds given `Kemal::Handler` to handlers chain.
|
||||||
|
@ -144,26 +142,14 @@ def send_file(env : HTTP::Server::Context, path : String, mime_type : String? =
|
||||||
condition = config.is_a?(Hash) && config["gzip"]? == true && filesize > minsize && Kemal::Utils.zip_types(file_path)
|
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")
|
if condition && request_headers.includes_word?("Accept-Encoding", "gzip")
|
||||||
env.response.headers["Content-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|
|
Gzip::Writer.open(env.response) do |deflate|
|
||||||
IO.copy(file, deflate)
|
IO.copy(file, deflate)
|
||||||
end
|
end
|
||||||
{% end %}
|
|
||||||
elsif condition && request_headers.includes_word?("Accept-Encoding", "deflate")
|
elsif condition && request_headers.includes_word?("Accept-Encoding", "deflate")
|
||||||
env.response.headers["Content-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|
|
Flate::Writer.open(env.response) do |deflate|
|
||||||
IO.copy(file, deflate)
|
IO.copy(file, deflate)
|
||||||
end
|
end
|
||||||
{% end %}
|
|
||||||
else
|
else
|
||||||
env.response.content_length = filesize
|
env.response.content_length = filesize
|
||||||
IO.copy(file, env.response)
|
IO.copy(file, env.response)
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
{% if !flag?(:without_zlib) %}
|
||||||
|
require "zlib"
|
||||||
|
{% end %}
|
||||||
|
|
||||||
module Kemal
|
module Kemal
|
||||||
class StaticFileHandler < HTTP::StaticFileHandler
|
class StaticFileHandler < HTTP::StaticFileHandler
|
||||||
# ameba:disable Metrics/CyclomaticComplexity
|
# ameba:disable Metrics/CyclomaticComplexity
|
||||||
|
|
|
@ -31,7 +31,9 @@ module Kemal
|
||||||
|
|
||||||
def call(context : HTTP::Server::Context)
|
def call(context : HTTP::Server::Context)
|
||||||
return call_next(context) unless context.ws_route_found? && websocket_upgrade_request?(context)
|
return call_next(context) unless context.ws_route_found? && websocket_upgrade_request?(context)
|
||||||
context.websocket.call(context)
|
content = context.websocket.call(context)
|
||||||
|
context.response.print(content)
|
||||||
|
context
|
||||||
end
|
end
|
||||||
|
|
||||||
def lookup_ws_route(path : String)
|
def lookup_ws_route(path : String)
|
||||||
|
|
Loading…
Reference in a new issue