Where to insert Rack::Deflater in the rack?

前端 未结 3 1839
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 06:50

I currently have the following:

use Rack::Rewrite
use Rack::Cache, {:verbose=>true, :metastore=>\"memcached://localhost:11211/rack-cache/meta\", :entitysto         


        
3条回答
  •  清酒与你
    2021-02-04 07:11

    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.

提交回复
热议问题