2011-07-28 11 views
3

圧縮データでHTTP :: Responseを作成する必要があります。コンテンツをgzipにするにはどうすればいいですか?適切なヘッダーを追加して、Compress :: Zlibを使用して自分で圧縮しますか?あるいは、LWPモジュールのどれかがこれを扱う方法を提供していますか?gzip圧縮HTTP :: Responseを作成するにはどうすればよいですか?

+0

[このperlmonksの記事](http://www.perlmonks.org/?node=858560)が役立つかもしれません。 – maerics

+0

この質問を参照してください:http://stackoverflow.com/questions/1285305/how-can-i-accept-gzip-compressed-content-using-lwpuseragent –

+0

これは、gzipされたコンテンツのダウンロードに関するものです。私の質問は、私のperlウェブサーバーを通してgzipされたコンテンツを提供することです。私は "abc 12345"のような内容を持っています。クライアント/ブラウザへのHTTP :: Responseとしてgzippedバージョンを送る必要があります。 – mrburns

答えて

2

これは必要なのですか?データをgzipし、Content-encodingヘッダーを設定して送信します。

use strict; 
use warnings; 

use HTTP::Response; 
use IO::Compress::Gzip qw(gzip); 

my $data = q(My cat's name is Buster); 

my $gzipped_data; 
my $gzip = gzip \$data => \$gzipped_data; 
print STDERR $gzipped_data; 

my $response = HTTP::Response->new; 

$response->code(200); 
$response->header('Content-type'  => 'text/plain'); 
$response->header('Content-encoding' => 'gzip'); 
$response->header('Content-length' => length $gzipped_data); 

$response->content($gzipped_data); 

print $response->as_string; 
関連する問題