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 calling body.each inside the block will break cases where body.each is not idempotent, such as when it is an IO instance.

: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, options = {})
  @app = app
  @condition = options[:if]
  @compressible_types = options[:include]
  @sync = options.fetch(:sync, true)
end