class Rack::Deflater

def call(env)

def call(env)
  status, headers, body = response = @app.call(env)
  unless should_deflate?(env, status, headers, body)
    return response
  end
  request = Request.new(env)
  encoding = Utils.select_best_encoding(%w(gzip identity),
                                        request.accept_encoding)
  # Set the Vary HTTP header.
  vary = headers["vary"].to_s.split(",").map(&:strip)
  unless vary.include?("*") || vary.any?{|v| v.downcase == 'accept-encoding'}
    headers["vary"] = vary.push("Accept-Encoding").join(",")
  end
  case encoding
  when "gzip"
    headers['content-encoding'] = "gzip"
    headers.delete(CONTENT_LENGTH)
    mtime = headers["last-modified"]
    mtime = Time.httpdate(mtime).to_i if mtime
    response[2] = GzipStream.new(body, mtime, @sync)
    response
  when "identity"
    response
  else # when nil
    # Only possible encoding values here are 'gzip', 'identity', and nil
    message = "An acceptable encoding for the requested resource #{request.fullpath} could not be found."
    bp = Rack::BodyProxy.new([message]) { body.close if body.respond_to?(:close) }
    [406, { CONTENT_TYPE => "text/plain", CONTENT_LENGTH => message.length.to_s }, bp]
  end
end