| 1 |
NAME |
| 2 |
|
| 3 |
Plack::Middleware::Deflater - Compress response body with Gzip or |
| 4 |
Deflate |
| 5 |
|
| 6 |
SYNOPSIS |
| 7 |
|
| 8 |
use Plack::Builder; |
| 9 |
|
| 10 |
builder { |
| 11 |
enable sub { |
| 12 |
my $app = shift; |
| 13 |
sub { |
| 14 |
my $env = shift; |
| 15 |
my $ua = $env->{HTTP_USER_AGENT} || ''; |
| 16 |
# Netscape has some problem |
| 17 |
$env->{"psgix.compress-only-text/html"} = 1 if $ua =~ m!^Mozilla/4!; |
| 18 |
# Netscape 4.06-4.08 have some more problems |
| 19 |
$env->{"psgix.no-compress"} = 1 if $ua =~ m!^Mozilla/4\.0[678]!; |
| 20 |
# MSIE (7|8) masquerades as Netscape, but it is fine |
| 21 |
if ( $ua =~ m!\bMSIE (?:7|8)! ) { |
| 22 |
$env->{"psgix.no-compress"} = 0; |
| 23 |
$env->{"psgix.compress-only-text/html"} = 0; |
| 24 |
} |
| 25 |
$app->($env); |
| 26 |
} |
| 27 |
}; |
| 28 |
enable "Deflater", |
| 29 |
content_type => ['text/css','text/html','text/javascript','application/javascript'], |
| 30 |
vary_user_agent => 1; |
| 31 |
sub { [200,['Content-Type','text/html'],["OK"]] } |
| 32 |
}; |
| 33 |
|
| 34 |
DESCRIPTION |
| 35 |
|
| 36 |
Plack::Middleware::Deflater is a middleware to encode your response |
| 37 |
body in gzip or deflate, based on Accept-Encoding HTTP request header. |
| 38 |
It would save the bandwidth a little bit but should increase the Plack |
| 39 |
server load, so ideally you should handle this on the frontend reverse |
| 40 |
proxy servers. |
| 41 |
|
| 42 |
This middleware removes Content-Length and streams encoded content, |
| 43 |
which means the server should support HTTP/1.1 chunked response or |
| 44 |
downgrade to HTTP/1.0 and closes the connection. |
| 45 |
|
| 46 |
CONFIGURATIONS |
| 47 |
|
| 48 |
content_type |
| 49 |
|
| 50 |
content_type => 'text/html', |
| 51 |
content_type => [ 'text/html', 'text/css', 'text/javascript', 'application/javascript', 'application/x-javascript' ] |
| 52 |
|
| 53 |
Content-Type header to apply deflater. if content-type is not |
| 54 |
defined, Deflater will try to deflate all contents. |
| 55 |
|
| 56 |
vary_user_agent |
| 57 |
|
| 58 |
vary_user_agent => 1 |
| 59 |
|
| 60 |
Add "User-Agent" to Vary header. |
| 61 |
|
| 62 |
ENVIRONMENT VALUE |
| 63 |
|
| 64 |
psgix.no-compress |
| 65 |
|
| 66 |
Do not apply deflater |
| 67 |
|
| 68 |
psgix.compress-only-text/html |
| 69 |
|
| 70 |
Apply deflater only if content_type is "text/html" |
| 71 |
|
| 72 |
plack.skip-deflater |
| 73 |
|
| 74 |
Skip all Deflater features |
| 75 |
|
| 76 |
Compare psgix.no-compress with plack.skip-deflater |
| 77 |
|
| 78 |
If no-compress is true, PM::Deflater skips gzip or deflate. But adds |
| 79 |
Vary: Accept-Encoding and Vary: User-Agent header. skip-deflater forces |
| 80 |
to skip all PM::Deflater feature, doesn't allow to add Vary header. |
| 81 |
|
| 82 |
LICENSE |
| 83 |
|
| 84 |
This software is licensed under the same terms as Perl itself. |
| 85 |
|
| 86 |
AUTHOR |
| 87 |
|
| 88 |
Tatsuhiko Miyagawa |
| 89 |
|
| 90 |
SEE ALSO |
| 91 |
|
| 92 |
Plack, http://httpd.apache.org/docs/2.2/en/mod/mod_deflate.html |
| 93 |
|