|
CGI::WebGzip - Perl extension for GZipping script output |
CGI::WebGzip - Perl extension for GZipping script output
# Usual code working with STDOUT: use CGI::WebGzip; print "Content-type: text/html\n\n"; print "Hello, world!";
# Lesser compression (by default 9, now - 5) use CGI::WebGzip(5);
# Set callback function which would be called after compressing,
# but before any output. You may set cookie in this function to
# display them later on the page (using JavaScript).
use CGI::WebGzip;
BEGIN {
CGI::WebGzip::setCallback(sub {
my ($nL, $oL) = (length $_[0], length $_[2]);
print sprintf "Set-Cookie: page_size=%d,%d; path=/\n", $oL, $nL;
return 1;
});
}
# Working together with CGI::WebOut. use CGI::WebGzip; use CGI::WebOut; print "Hello, world!";
# Work in FastCGI environment.
require CGI::WebGzip;
while (read request) {
CGI::WebGzip::import; # captures output
...
CGI::WebGzip::flush(); # releases output
}
In PHP, you may write: ob_start("ob_gzhandler") and get all the output
GZip-ed automatically. CGI::WebGzip does the same thing. Is you include this module
in the beginning of your program, it whill capture all the output. When
the script ends, CGI::WebGzip compresses captured data and send it to browser.
If browser is incompatible with GZip encoding, output will not be captured, and data will not be compressed.
flush()import() call
(see synopsis above).
getAbility()isCompressibleType($type)bool callback(string $compressedBody, string $headers, string $originalBody)
Returns previous callback reference.
setLevel($level)getStatus()$compressedBody only.
Input headers can be modified, thus this function returns $modifiedHeaders.
In $status compression feruse message is returned (or undef if everything is OK).
This function can be used exactly as PHPs ob_gzhandler().
None by default.
CGI::WebGzip depends on Compress::Zlib only. If this library is not found, no error messages are generated.
Dmitry Koterov <koterov at cpan dot org>
the Compress::Zlib manpage, the CGI::WebOut manpage
|
CGI::WebGzip - Perl extension for GZipping script output |