Included Modules

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
293:     def initialize(ops={})
294:       @options = ops
295:       @always_deflate = ops[:always_deflate] || false
296:     end

Public Instance Methods

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

Private Instance Methods

deflate(stream) click to toggle source
     # File lib/mongrel/handlers.rb, line 308
308:       def deflate(stream)
309:         deflater = Deflate.new(
310:           DEFAULT_COMPRESSION,
311:           # drop the zlib header which causes both Safari and IE to choke
312:           -MAX_WBITS, 
313:           DEF_MEM_LEVEL,
314:           DEFAULT_STRATEGY)
315: 
316:         stream.rewind
317:         gzout = StringIO.new(deflater.deflate(stream.read, FINISH))
318:         stream.close
319:         gzout.rewind
320:         gzout
321:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.