[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Trouble with gzip output compression

szymon.rozga

5/25/2006 4:54:00 PM

I am using the Rails output_compression plugin, but this applies to
nonRails applications as well. I am trying to compress a large amount
of output and send it. However, the browser doesn't seem to decode the
gzip properly (instead of some tables I need, it displays a lot of
junk) The code in question is the following:

def compress_output
return unless accepts_gzip?
output = StringIO.new
def output.close
# Zlib does a close. Bad Zlib...
rewind
end
gz = Zlib::GzipWriter.new(output)
gz.write(response.body)
gz.close
if output.length < response.body.length
@old_response_body = response.body
response.body = output.string
response.headers['Content-encoding'] = @compression_encoding
end
end

def accepts_gzip?
return false unless GZIP_SUPPORTED
accepts = request.env['HTTP_ACCEPT_ENCODING']
return false unless accepts && accepts =~ /(x-gzip|gzip)/
@compression_encoding = $1
true
end

Is there any reason that this code would _not_ properly compress the
output?

1 Answer

Robert Klemme

5/26/2006 10:17:00 AM

0

Szymon Rozga wrote:
> I am using the Rails output_compression plugin, but this applies to
> nonRails applications as well. I am trying to compress a large amount
> of output and send it. However, the browser doesn't seem to decode the
> gzip properly (instead of some tables I need, it displays a lot of
> junk) The code in question is the following:
>
> def compress_output
> return unless accepts_gzip?
> output = StringIO.new
> def output.close
> # Zlib does a close. Bad Zlib...
> rewind
> end
> gz = Zlib::GzipWriter.new(output)
> gz.write(response.body)
> gz.close
> if output.length < response.body.length
> @old_response_body = response.body
> response.body = output.string
> response.headers['Content-encoding'] = @compression_encoding
> end
> end
>
> def accepts_gzip?
> return false unless GZIP_SUPPORTED
> accepts = request.env['HTTP_ACCEPT_ENCODING']
> return false unless accepts && accepts =~ /(x-gzip|gzip)/
> @compression_encoding = $1
> true
> end
>
> Is there any reason that this code would _not_ properly compress the
> output?
>

Do you indicate compression via a HTTP header? Maybe that's the missing
part.

robert