Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Trouble with gzip output compression

Reply
Thread Tools

Trouble with gzip output compression

 
 
Szymon Rozga
Guest
Posts: n/a
 
      05-25-2006
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?

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      05-26-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gzip compression with SOAP Fernando Silva Ruby 0 12-29-2009 02:17 PM
GZip output compression with AJAX Mike P2 ASP .Net 4 06-12-2007 11:29 AM
Gzip compression and ASP.NET Anders K. Jacobsen [DK] ASP .Net 4 12-31-2004 10:17 AM
GZip Compression for IIS 5.0/ASP .NET Chad A. Beckner ASP .Net 1 07-23-2004 02:13 AM
GZIP output and input strange behaviour Nikk & Jak Anderson Java 2 04-26-2004 08:11 PM



Advertisments