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

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

问题描述

在使用方法 时,告诉 Rails 使用弱而不是强 ETAG 的最佳方法是什么?fresh_whenstale??

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

我问的原因是 nginx(正确)从响应中删除强 ETAG 标头时启用动态 gzip 压缩.

推荐答案

我从@grosser 的回答中获取了代码并将其变成了 Gem:

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

您可以将其添加到您的 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 生成的 e-tags,无论是带有 Rack::ETag 还是带有显式 e-tags 都将被转换为 weak.使用修补过的或版本 > 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天全站免登陆