我想为从Rails的Accept-Ranges none
文件夹中请求的视频文件设置public
。该视频文件不在我的资产管道中,因此该视频仅位于/public/videos/example.mp4
。如何在开发模式下设置这些HTTP标头?我尝试在config.public_file_server.headers
中编辑development.rb
哈希,但我不认为这是正确的配置。
config.public_file_server.headers = {
'Cache-Control' => "public, max-age=15768000",
"Accept-Ranges" => "none"
}
据我在Rails 4中所知,除了Cache-Control
之外,无法在文件上设置其他响应头。这是一个限制。
但是with changes in Rails 5,您可以设置任何所需的标头,并且这是进行开发的正确位置:config.public_file_server.headers
中的development.rb
但是,要使更改生效,必须在启动服务器之前使用create a development cache使用rails dev: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
dev-cache和服务器
$ rails dev:cache
Development mode is now being cached.
$ rails s
请求:
$ curl -sI http://localhost:3000/car-images-silhouettes/back.png | grep Accept-Ranges
Accept-Ranges: none