Rails中弱ETAG? [英] Weak ETAGs in Rails?

查看:156
本文介绍了Rails中弱ETAG?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用方法<$ c时告诉rails使用弱而非强ETAG 的最佳方法是什么? $ c> fresh_when 和陈旧?

What is the best way to tell rails to use weak instead of strong ETAGs when using methods fresh_when and stale??

我问的原因是 nginx(正确)在启用动态gzipping时从响应中删除强大的ETAG标头

推荐答案

我从@ grosser的答案中取出代码并将其转换为Gem:

I took the code from @grosser's answer and turned it into a Gem:

  • https://rubygems.org/gems/rails_weak_etags
  • https://github.com/johnnaegle/rails_weak_etags

你可以将此添加到您的gemfile:

You can just add this to your gemfile:

gem 'rails_weak_etags'

它将被安装到您的中间件之前 Rack :: ConditionalGet

And it will be installed into your middleware before Rack::ConditionalGet:

> bundle exec rake middleware
....
use RailsWeakEtags::Middleware
use Rack::ConditionalGet
use Rack::ETag
....

然后rails生成的所有电子标签,无论是使用Rack :: ETag还是使用显式电子标签,都将是转为弱势。使用补丁或版本> 1.7.3的nginx,然后将允许您使用电子标签和gzip压缩。

Then all the e-tags generated by rails, either with Rack::ETag or with explicit e-tags will be converted to weak. Using a patched, or version > 1.7.3 of nginx, will then let you use e-tags and gzip compression.

RACK 1.6默认etags为弱 - 如果升级,这个gem不再有用。

RACK 1.6 defaults etags to weak - this gem is no longer helpful if you upgrade.

这篇关于Rails中弱ETAG?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆