Method: Rack::Deflater#initialize
- Defined in:
- lib/rack/deflater.rb
#initialize(app, options = {}) ⇒ Deflater
Creates Rack::Deflater middleware. Options:
- :if
-
a lambda enabling / disabling deflation based on returned boolean value (e.g
use Rack::Deflater, :if => lambda { |*, body| sum=0; body.each { |i| sum += i.length }; sum > 512 }). However, be aware that callingbody.eachinside the block will break cases wherebody.eachis not idempotent, such as when it is anIOinstance. - :include
-
a list of content types that should be compressed. By default, all content types are compressed.
- :sync
-
determines if the stream is going to be flushed after every chunk. Flushing after every chunk reduces latency for time-sensitive streaming applications, but hurts compression and throughput. Defaults to
true.
39 40 41 42 43 44 |
# File 'lib/rack/deflater.rb', line 39 def initialize(app, = {}) @app = app @condition = [:if] @compressible_types = [:include] @sync = .fetch(:sync, true) end |