Fix StaticFileHandler failing spec (#599)

This commit is contained in:
jinn999 2021-03-07 12:29:49 +01:00 committed by GitHub
parent f71a83e2c4
commit 8d0875f64c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,6 +1,6 @@
require "./spec_helper"
private def handle(request, fallthrough = true)
private def handle(request, fallthrough = true, decompress = true)
io = IO::Memory.new
response = HTTP::Server::Response.new(io)
context = HTTP::Server::Context.new(request, response)
@ -8,7 +8,7 @@ private def handle(request, fallthrough = true)
handler.call context
response.close
io.rewind
HTTP::Client::Response.from_io(io)
HTTP::Client::Response.from_io(io, decompress: decompress)
end
describe Kemal::StaticFileHandler do
@ -51,7 +51,7 @@ describe Kemal::StaticFileHandler do
it "should gzip a file if config is true, headers accept gzip and file is > 880 bytes" do
serve_static({"gzip" => true, "dir_listing" => true})
headers = HTTP::Headers{"Accept-Encoding" => "gzip, deflate, sdch, br"}
response = handle HTTP::Request.new("GET", "/dir/bigger.txt", headers)
response = handle HTTP::Request.new("GET", "/dir/bigger.txt", headers), decompress: false
response.status_code.should eq(200)
response.headers["Content-Encoding"].should eq "gzip"
end
@ -59,7 +59,7 @@ describe Kemal::StaticFileHandler do
it "should not gzip a file if config is true, headers accept gzip and file is < 880 bytes" do
serve_static({"gzip" => true, "dir_listing" => true})
headers = HTTP::Headers{"Accept-Encoding" => "gzip, deflate, sdch, br"}
response = handle HTTP::Request.new("GET", "/dir/test.txt", headers)
response = handle HTTP::Request.new("GET", "/dir/test.txt", headers), decompress: false
response.status_code.should eq(200)
response.headers["Content-Encoding"]?.should be_nil
end
@ -67,7 +67,7 @@ describe Kemal::StaticFileHandler do
it "should not gzip a file if config is false, headers accept gzip and file is > 880 bytes" do
serve_static({"gzip" => false, "dir_listing" => true})
headers = HTTP::Headers{"Accept-Encoding" => "gzip, deflate, sdch, br"}
response = handle HTTP::Request.new("GET", "/dir/bigger.txt", headers)
response = handle HTTP::Request.new("GET", "/dir/bigger.txt", headers), decompress: false
response.status_code.should eq(200)
response.headers["Content-Encoding"]?.should be_nil
end