Fix StaticFileHandler failing spec (#599)
This commit is contained in:
parent
f71a83e2c4
commit
8d0875f64c
1 changed files with 5 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
require "./spec_helper"
|
require "./spec_helper"
|
||||||
|
|
||||||
private def handle(request, fallthrough = true)
|
private def handle(request, fallthrough = true, decompress = true)
|
||||||
io = IO::Memory.new
|
io = IO::Memory.new
|
||||||
response = HTTP::Server::Response.new(io)
|
response = HTTP::Server::Response.new(io)
|
||||||
context = HTTP::Server::Context.new(request, response)
|
context = HTTP::Server::Context.new(request, response)
|
||||||
|
@ -8,7 +8,7 @@ private def handle(request, fallthrough = true)
|
||||||
handler.call context
|
handler.call context
|
||||||
response.close
|
response.close
|
||||||
io.rewind
|
io.rewind
|
||||||
HTTP::Client::Response.from_io(io)
|
HTTP::Client::Response.from_io(io, decompress: decompress)
|
||||||
end
|
end
|
||||||
|
|
||||||
describe Kemal::StaticFileHandler do
|
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
|
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})
|
serve_static({"gzip" => true, "dir_listing" => true})
|
||||||
headers = HTTP::Headers{"Accept-Encoding" => "gzip, deflate, sdch, br"}
|
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.status_code.should eq(200)
|
||||||
response.headers["Content-Encoding"].should eq "gzip"
|
response.headers["Content-Encoding"].should eq "gzip"
|
||||||
end
|
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
|
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})
|
serve_static({"gzip" => true, "dir_listing" => true})
|
||||||
headers = HTTP::Headers{"Accept-Encoding" => "gzip, deflate, sdch, br"}
|
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.status_code.should eq(200)
|
||||||
response.headers["Content-Encoding"]?.should be_nil
|
response.headers["Content-Encoding"]?.should be_nil
|
||||||
end
|
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
|
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})
|
serve_static({"gzip" => false, "dir_listing" => true})
|
||||||
headers = HTTP::Headers{"Accept-Encoding" => "gzip, deflate, sdch, br"}
|
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.status_code.should eq(200)
|
||||||
response.headers["Content-Encoding"]?.should be_nil
|
response.headers["Content-Encoding"]?.should be_nil
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue