Jeremy - you will need to check the "Accept-Encoding" http header to determine 
whether the browser can accept compressed output. If you find the word "gzip" 
(/\bgzip\b/) in this header's value you can compress the output (with the 
method below).

If you are going to send compressed output, you will need to add the following 
headers to your response:
                Content-Encoding: gzip
                Vary: Accept-Encoding

Assuming you've assembled all output that it supposed to be sent to the client 
in a variable called "$out", you can use the code below (which uses 
Compress::Zlib) to gzip-compress the clear text:

  my ($d, $st) = Compress::Zlib::deflateInit(-Level => 9);
  my ($cout, $s) = $d->deflate($out);
  my ($coutF, $sf) = $d->flush();
  $cout = $cout.$coutF;
  my $pre = pack('CCCCCCCC', 0x1f,0x8b,0x08,0x00,0x00,0x00,0x00,0x00);
  $cout = $pre . substr($cout, 0, -4) . pack('V', Compress::Zlib::crc32($out)) 
. pack('V', length($out));
  print $cout;

This code was taken from a CPAN module (duh - forgot which one) and it's 
working just fine here in various scripts.

I'd still urge you to use one of the standard modules (like CGI), because you 
are not going to reinvent the wheel that way. If you are running on a mod_perl 
server (which you should if you make heavy use of perl), then module overhead 
is much less of an issue.


-          Tobias

From: [email protected] 
[mailto:[email protected]] On Behalf Of Jer A
Sent: Wednesday, March 25, 2009 2:01 PM
To: [email protected]
Subject: http 1.1 compression and cgi output


so I have this cgi that returns data from a database, that has over 13,000 
possible queries for output.
some of the queries output alot of data.

I would like to use http 1.1 compression (deflate,GZip), but as this is a cgi 
script, I do not want to much of a performance hit....I try to load minimal 
modules (please note: I do not use CGI.pm)
I do not think that caching the compressed data will be any good, as it will 
make my database huge, and I do not have alot of space, as well the db may be 
updated frequently.


I am new to working with databases, and http 1.1 compression, are there any 
alternatives?

-Jeremy

_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to