Transfer-encoding: gzip

Magnus Naeslund
Sun, 18 Mar 2007 22:43:53 -0000

Magnus Naeslund wrote:
>
>     def compress_if_possible(str)
>       enc = request.env[HTTP_ACCEPT_ENCODING]
>       return str if enc.nil? or enc.include?(''deflate'')
== false
>       headers[''Content-Encoding''] =
''deflate''
>
>       # Shamelessly stolen from mongrels deflate filter
> 		  deflater = Zlib::Deflate.new(
> 		    Zlib::DEFAULT_COMPRESSION,
> 		    # drop the zlib header which causes both Safari and IE to choke
>         -(Zlib::MAX_WBITS),
>         Zlib::DEF_MEM_LEVEL,
>         Zlib::DEFAULT_STRATEGY)
>
>       return deflater.deflate(str, Zlib::FINISH)
>     end
>


Remember to user deflater.close before returning, if someone copies this code :)

Regards,
Magnus - butterfingers