Where to insert Rack::Deflater in the rack?

Binary Logic picture Binary Logic · Aug 30, 2011 · Viewed 9.4k times · Source

I currently have the following:

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

I may be wrong, but wouldn't it make sense to move Deflater to the top? This way any and all traffic is gzipped.

Thanks for the help.

Answer

Parker Selbert picture Parker Selbert · Oct 1, 2011

The simplest way to insert it is directly in your config.ru:

require ::File.expand_path('../config/environment',  __FILE__)
use Rack::Deflater
run My::Application

To confirm it is working start up your app and hit it with curl:

curl -i --head "Accept-Encoding: gzip,deflate" http://localhost:5000

Which should return the headers:

Vary: Accept-Encoding
Content-Encoding: gzip

And a beautifully gzipped response.