mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Allow headers in built-in static file server
This commit is contained in:
parent
2cfe789587
commit
607aaeffe3
4 changed files with 41 additions and 0 deletions
12
spec/static/dir/index.html
Normal file
12
spec/static/dir/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>title</title>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- page content -->
|
||||
</body>
|
||||
</html>
|
|
@ -130,4 +130,24 @@ describe Kemal::StaticFileHandler do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
it "should handle setting custom headers" do
|
||||
headers = Proc(HTTP::Server::Response, String, File::Stat, Void).new do |response, path, stat|
|
||||
if path =~ /\.html$/
|
||||
response.headers.add("Access-Control-Allow-Origin", "*")
|
||||
end
|
||||
response.headers.add("Content-Size", stat.size.to_s)
|
||||
end
|
||||
|
||||
static_headers(&headers)
|
||||
|
||||
response = handle HTTP::Request.new("GET", "/dir/test.txt")
|
||||
response.headers.has_key?("Access-Control-Allow-Origin").should be_false
|
||||
response.headers["Content-Size"].should eq(
|
||||
File.stat("#{__DIR__}/static/dir/test.txt").size.to_s
|
||||
)
|
||||
|
||||
response = handle HTTP::Request.new("GET", "/dir/index.html")
|
||||
response.headers["Access-Control-Allow-Origin"].should eq("*")
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue