Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to insert Rack::Deflater in the rack?

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.

like image 662
Binary Logic Avatar asked Aug 29 '11 22:08

Binary Logic


1 Answers

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.

like image 60
Parker Selbert Avatar answered Oct 02 '22 12:10

Parker Selbert