class HerokuDeflater::SkipBinary

Add a no-transform Cache-Control header to binary types, so they won't get gzipped

Constants

WHITELIST

Public Class Methods

new(app) click to toggle source
# File lib/heroku-deflater/skip_binary.rb, line 4
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/heroku-deflater/skip_binary.rb, line 18
def call(env)
  status, headers, body = @app.call(env)
  headers = Rack::Utils::HeaderHash.new(headers)
  content_type = headers['Content-Type']
  cache_control = headers['Cache-Control'].to_s.downcase

  unless cache_control.include?('no-transform') || WHITELIST.any? { |type| type === content_type }
    if cache_control.empty?
      headers['Cache-Control'] = 'no-transform'
    else
      headers['Cache-Control'] += ', no-transform'
    end
  end

  body.close if body.respond_to?(:close)
  [status, headers, body]
end