Transfer-encoding: gzip
Magnus Naeslund
mag at kite.se
Sun Mar 18 18:43:53 EDT 2007
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
More information about the Merb-devel
mailing list