Class: Mongrel::DeflateFilter

Inherits:
HttpHandler show all
Includes:
Zlib
Defined in:
lib/mongrel/handlers.rb

Overview

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.

Constant Summary collapse

HTTP_ACCEPT_ENCODING =
"HTTP_ACCEPT_ENCODING"

Instance Attribute Summary

Attributes inherited from HttpHandler

#listener, #request_notify

Instance Method Summary collapse

Methods inherited from HttpHandler

#request_begins, #request_progress

Constructor Details

#initialize(ops = {}) ⇒ DeflateFilter

Returns a new instance of DeflateFilter.


293
294
295
296
# File 'lib/mongrel/handlers.rb', line 293

def initialize(ops={})
  @options = ops
  @always_deflate = ops[:always_deflate] || false
end

Instance Method Details

#process(request, response) ⇒ Object


298
299
300
301
302
303
304
305
# 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