From cfedc7c538fb4b93138669bfde94f41f3ddee1ce Mon Sep 17 00:00:00 2001 From: Serdar Dogruyol Date: Thu, 24 Aug 2017 01:24:19 +0300 Subject: [PATCH] Add docs for static_headers --- src/kemal/helpers/helpers.cr | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/kemal/helpers/helpers.cr b/src/kemal/helpers/helpers.cr index 204336c..3edb826 100644 --- a/src/kemal/helpers/helpers.cr +++ b/src/kemal/helpers/helpers.cr @@ -201,6 +201,16 @@ def gzip(status : Bool = false) add_handler HTTP::CompressHandler.new if status end +# Adds headers to `Kemal::StaticFileHandler`. This is especially useful for `CORS`. +# +# ```ruby +# static_headers do |response, filepath, filestat| +# if filepath =~ /\.html$/ +# response.headers.add("Access-Control-Allow-Origin", "*") +# end +# response.headers.add("Content-Size", filestat.size.to_s) +# end +# ``` def static_headers(&headers : HTTP::Server::Response, String, File::Stat -> Void) Kemal.config.static_headers = headers end