Ruby on rails 为公用文件夹中的文件设置HTTP头
我想为从Rails中的Ruby on rails 为公用文件夹中的文件设置HTTP头,ruby-on-rails,ruby,ruby-on-rails-5,Ruby On Rails,Ruby,Ruby On Rails 5,我想为从Rails中的public文件夹请求的视频文件设置Accept Ranges none。视频文件不在我的资产管道中,因此视频仅存在于/public/videos/example.mp4。如何在开发模式下设置这些HTTP头?我试图在development.rb中编辑config.public\u文件\u server.headers散列,但我认为这不是正确的配置 config.public_file_server.headers = { 'Cache-Control' => "p
public
文件夹请求的视频文件设置Accept Ranges none
。视频文件不在我的资产管道中,因此视频仅存在于/public/videos/example.mp4
。如何在开发模式下设置这些HTTP头?我试图在development.rb
中编辑config.public\u文件\u server.headers
散列,但我认为这不是正确的配置
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=15768000",
"Accept-Ranges" => "none"
}
据我所知,在Rails 4中,除了
缓存控制
之外,不能对文件设置其他响应头。这是一个限制
但是,您可以在development.rb中设置所需的任何标题,这是进行开发的正确位置:config.public\u file\u server.headers
但是,为了使更改生效,您必须在启动服务器之前使用railsdev:cache
演示:
development.rb:
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800',
'Accept-Ranges' => 'none'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
$ curl -sI http://localhost:3000/car-images-silhouettes/back.png | grep Accept-Ranges
Accept-Ranges: none
开发缓存和服务器
$ rails dev:cache
Development mode is now being cached.
$ rails s
请求:
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800',
'Accept-Ranges' => 'none'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
$ curl -sI http://localhost:3000/car-images-silhouettes/back.png | grep Accept-Ranges
Accept-Ranges: none
嘿,我的答案解决问题了吗?