Reading gzip'ed websites

at 2010-01-08 in Examples by friebe (0 comments)

To reduce bandwidth some servers have their content zipped using solutions such as Apache's mod_deflate. This is done only if the Accept-Encoding request header contains the string gzip. Combining the XP Framework's peer.http API with the new io.streams.GzDecompressingInputStream one can accomplish this compression:

  $conn= new HttpConnection($args[0]);
$response= $conn->get(array(), array('Accept-Encoding' => 'gzip'));

if
('gzip' == $response->getHeader('Content-Encoding')) {
$in= new GzDecompressingInputStream($r->getInputStream());
} else {
$in= $r->getInputStream();
}

// Now read $in as with any other stream...



Subscribe

You can subscribe to the XP framework's news by using RSS syndication.


Categories

News
General
PHP5
Announcements
RFCs
Further reading
Examples
Editorial
EASC
Experiments
Unittests
Databases
5.8-SERIES
Unicode
Language
5.9-SERIES

Related

Find related articles by a search for «Reading».