我目前有以下内容:
use Rack::Rewrite
use Rack::Cache, {:verbose=>true, :metastore=>"memcached://localhost:11211/rack-cache/meta", :entitystore=>"memcached://localhost:11211/rack-cache/body"}
use Rack::Rewrite
use Rack::Lock
use Rack::Deflater
use ActionController::Failsafe
use #<Class:0x007fb34be9ac90>
use ActionController::Session::DalliStore, #<Proc:0x007fb34bea3638@(eval):8 (lambda)>
use Rails::Rack::Metal
use ActionController::ParamsParser
use Rack::MethodOverride
use Rack::Head
use ActionController::StringCoercion
use Sass::Plugin::Rack
use Hassle
use ActiveRecord::ConnectionAdapters::ConnectionManagement
use ActiveRecord::QueryCache
run ActionController::Dispatcher.new
我可能是错的,但将 Deflater 移至顶部是否有意义?这样所有的流量都被 gzip 压缩了。
感谢您的帮助。
最佳答案
最简单的插入方式是直接在您的 config.ru 中:
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run My::Application
要确认它正在运行,请启动您的应用并使用 curl 对其进行访问:
curl -i --head "Accept-Encoding: gzip,deflate" http://localhost:5000
哪个应该返回标题:
Vary: Accept-Encoding
Content-Encoding: gzip
还有一个精美的 gzip 响应。
关于ruby-on-rails - 在 Rack 中的哪里插入 Rack::Deflater?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7236583/