class Mongrel::DeflateFilter

When added to a config script (-S in mongrel_rails) it will look at the client's allowed response types and then gzip compress anything that is going out.

Valid option is :always_deflate => false which tells the handler to deflate everything even if the client can't handle it.

Constants

HTTP_ACCEPT_ENCODING

Public Class Methods

new(ops={}) click to toggle source
# File lib/mongrel/handlers.rb, line 293
def initialize(ops={})
  @options = ops
  @always_deflate = ops[:always_deflate] || false
end

Public Instance Methods

process(request, response) click to toggle source
# File lib/mongrel/handlers.rb, line 298
def process(request, response)
  accepts = request.params[HTTP_ACCEPT_ENCODING]
  # only process if they support compression
  if @always_deflate or (accepts and (accepts.include? "deflate" and not response.body_sent))
    response.header["Content-Encoding"] = "deflate"
    response.body = deflate(response.body)
  end
end