Class: Mongrel::DeflateFilter
- Inherits:
-
HttpHandler
- Object
- HttpHandler
- Mongrel::DeflateFilter
- 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
Instance Method Summary collapse
-
#initialize(ops = {}) ⇒ DeflateFilter
constructor
A new instance of DeflateFilter.
- #process(request, response) ⇒ Object
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 |