簡體   English   中英

何處將Rack :: Deflater插入機架?

[英]Where to insert Rack::Deflater in the rack?

我目前有以下內容:

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

還有一個精美的反應。

我必須很早地插入它(在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

回應Maletor,關於如何將某些文件排除在gzip之外,請參閱:

http://icelab.com.au/articles/wrapping-rack-middleware-to-exclude-certain-urls-for-rails-streaming-responses/

嘗試過(在Sinatra),效果很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM