我为开发环境在本地运行Webricks / Thin服务器,但是我无法在响应中返回Etag。
我尝试了在SO上建议的各种选项,以添加Etag或ConditionalGet机架中间件组件,但无济于事。 这是我的development.rb文件的片段
config.middleware.use Rack::Cors do
allow do
origins 'xyz:3000', 'abc:3000'
resource '*', :headers => :any, :methods => [:get, :post, :options]
end
config.middleware.insert_before(Rack::Cors, Rack::ConditionalGet)
config.consider_all_requests_local = true
config.action_controller.perform_caching = true
这是来自请求的示例响应标头,并且缺少Etag标头或HTTP_IF_NONE_MATCH和HTTP_IF_MODIFIED_SINCE标头,因此所有请求均返回200 OK,而从未返回304 Not Modified
> curl --head -I mylocalhosturl
HTTP/1.1 200 OK
Last-Modified: Mon, 04 Feb 2013 23:49:11 GMT
Content-Type: application/json; charset=utf-8
Cache-Control: must-revalidate, private, max-age=0
X-Meta-Request-Version: 0.2.1
X-Ua-Compatible: IE=Edge
X-Request-Id: a06b5c3aeff8191ad22ab7d23433b076
X-Runtime: 0.217688
X-Rack-Cache: miss
X-Miniprofiler-Ids: ["470heu3ps6wht3tuqgdr","qdjrpkjus6pzw6ed28ex","egfngxkdtl2f2m1w7r9n","b3dlozxj3hyb9bq2i2fi","k7x41fq7anewz5jf0nm1","unojexyqklkjdew8dkti","rjwo48jd8pw8c0h0jb38","82d8g9o6agzoam7acxgi","tk577xwtgtfn7u1mrvqo","e8ih8byjbm2jfmbyl5tf"]
Content-Length: 0
Server: WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16)
Date: Mon, 03 Jun 2013 18:34:31 GMT
Connection: Keep-Alive
Set-Cookie: __profilin=p%3Dt; path=/
Set-Cookie: __profilin=p%3Dt; path=/
Set-Cookie: __profilin=p%3Dt; path=/
有趣的是,使用类似配置AFAIK的生产环境不是问题,但使用nginx / 1.2.0作为服务器。 任何在Rails开发模式下启用Etags的想法都值得赞赏。
从项目中删除rack-mini-profiler
gem,然后重新启动服务器。
出于某种原因rack-mini-profiler
宝石会剥去Etags。 我找到这则SO帖子是因为我一直想弄清楚为什么它会剥离Etags。
更新资料
您还可以根据如下官方文档来禁用该行为
Rack::MiniProfiler.config.disable_caching = false
请注意,禁用该行为可能会导致在文档中提到的rack-mini-profiler
一些讨厌的错误