我在本地为我的开发环境运行 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 的想法都值得赞赏。