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