我目前有以下内容:
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我可能错了,但把放气带移到顶端不是很有意义吗?这样,任何和所有的流量都会被gzipped压缩。
谢谢你的帮助。
发布于 2011-10-01 06:24:23
插入它的最简单方法是直接在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和一个漂亮的gzipped回复。
发布于 2012-10-25 12:19:22
我不得不在很早的时候(在ActionDispatch::Static之前)插入它,如下所示:
# production.rb
config.middleware.insert_before ActionDispatch::Static, Rack::Deflater您可以使用rake middleware进行确认(尽管这将查看您的开发设置)
> rake middleware
use Rack::Deflater
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f8e18455e90>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Remotipart::Middleware
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use Warden::Manager
use Rack::Mongoid::Middleware::IdentityMap
use Rack::Pjax
run MyApp::Application.routes发布于 2012-11-29 05:23:46
作为对Maletor的回应,有关如何从gzip中排除某些文件,请参阅:
http://icelab.com.au/articles/wrapping-rack-middleware-to-exclude-certain-urls-for-rails-streaming-responses/
我试过了(在Sinatra),效果很好。
https://stackoverflow.com/questions/7236583
复制相似问题