diff options
author | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-05-23 03:58:37 +0000 |
---|---|---|
committer | zedshaw <zedshaw@19e92222-5c0b-0410-8929-a290d50e31e9> | 2006-05-23 03:58:37 +0000 |
commit | 25f477099bc025e95e423a713c9f5e3b29b3d4e5 (patch) | |
tree | b284ac466828c63d0ca7748e4f40f707dba70e87 /lib/mongrel/handlers.rb | |
parent | 4905d82fc0f96a79f2d3a5d9eaf93c1112684d7c (diff) | |
download | unicorn-25f477099bc025e95e423a713c9f5e3b29b3d4e5.tar.gz |
git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@206 19e92222-5c0b-0410-8929-a290d50e31e9
Diffstat (limited to 'lib/mongrel/handlers.rb')
-rw-r--r-- | lib/mongrel/handlers.rb | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/mongrel/handlers.rb b/lib/mongrel/handlers.rb index cccf365..1134bdf 100644 --- a/lib/mongrel/handlers.rb +++ b/lib/mongrel/handlers.rb @@ -28,6 +28,7 @@ module Mongrel # should be implemented using the HttpHandlerPlugin mixin. # class HttpHandler + attr_reader :header_only def process(request, response) end @@ -40,9 +41,11 @@ module Mongrel # the process method later. module HttpHandlerPlugin attr_reader :options + attr_reader :header_only def initialize(options={}) @options = options + @header_only = false end def process(request, response) @@ -261,4 +264,30 @@ module Mongrel end end + + + # 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. + class DeflateCompressFilter < HttpHandler + HTTP_ACCEPT_ENCODING = "HTTP_ACCEPT_ENCODING" + + def initialize(ops) + @options = ops + end + + def process(request, response) + accepts = request.params[HTTP_ACCEPT_ENCODING] + # only process if they support compression + if accepts.include? "gzip" or accepts.include? "deflate" and not response.body_sent + head["Content-Encoding"] = "deflate" + # we can't just rewind the body and gzip it since the body could be an attached file + response.body.rewind + gzout << Zlib::Deflate.deflate(response.body.read) + gzout.rewind + response.body.close + response.body = gzout + end + end + end end |