1Plack::Middleware::DeflUasteerr(C3o)ntributed Perl DocumPelnatcakt:i:oMniddleware::Deflater(3)
2
3
4

NAME

6       Plack::Middleware::Deflater - Compress response body with Gzip or
7       Deflate
8

SYNOPSIS

10         use Plack::Builder;
11
12         builder {
13           enable sub {
14               my $app = shift;
15               sub {
16                   my $env = shift;
17                   my $ua = $env->{HTTP_USER_AGENT} || '';
18                   # Netscape has some problem
19                   $env->{"psgix.compress-only-text/html"} = 1 if $ua =~ m!^Mozilla/4!;
20                   # Netscape 4.06-4.08 have some more problems
21                    $env->{"psgix.no-compress"} = 1 if $ua =~ m!^Mozilla/4\.0[678]!;
22                   # MSIE (7|8) masquerades as Netscape, but it is fine
23                   if ( $ua =~ m!\bMSIE (?:7|8)! ) {
24                       $env->{"psgix.no-compress"} = 0;
25                       $env->{"psgix.compress-only-text/html"} = 0;
26                   }
27                   $app->($env);
28               }
29           };
30           enable "Deflater",
31               content_type => ['text/css','text/html','text/javascript','application/javascript'],
32               vary_user_agent => 1;
33           sub { [200,['Content-Type','text/html'],["OK"]] }
34         };
35

DESCRIPTION

37       Plack::Middleware::Deflater is a middleware to encode your response
38       body in gzip or deflate, based on "Accept-Encoding" HTTP request
39       header. It would save the bandwidth a little bit but should increase
40       the Plack server load, so ideally you should handle this on the
41       frontend reverse proxy servers.
42
43       This middleware removes "Content-Length" and streams encoded content,
44       which means the server should support HTTP/1.1 chunked response or
45       downgrade to HTTP/1.0 and closes the connection.
46

CONFIGURATIONS

48       content_type
49             content_type => 'text/html',
50             content_type => [ 'text/html', 'text/css', 'text/javascript', 'application/javascript', 'application/x-javascript' ]
51
52           Content-Type header to apply deflater. if content-type is not
53           defined, Deflater will try to deflate all contents.
54
55       vary_user_agent
56             vary_user_agent => 1
57
58           Add "User-Agent" to Vary header.
59

ENVIRONMENT VALUE

61       psgix.no-compress
62           Do not apply deflater
63
64       psgix.compress-only-text/html
65           Apply deflater only if content_type is "text/html"
66
67       plack.skip-deflater
68           Skip all Deflater features
69
70   Compare psgix.no-compress with plack.skip-deflater
71       If no-compress is true, PM::Deflater skips gzip or deflate. But adds
72       Vary: Accept-Encoding and Vary: User-Agent header. skip-deflater forces
73       to skip all PM::Deflater feature, doesn't allow to add Vary header.
74

LICENSE

76       This software is licensed under the same terms as Perl itself.
77

AUTHOR

79       Tatsuhiko Miyagawa
80

SEE ALSO

82       Plack, <http://httpd.apache.org/docs/2.2/en/mod/mod_deflate.html>
83
84
85
86perl v5.32.0                      2020-07-28    Plack::Middleware::Deflater(3)
Impressum