diff --git a/README b/README index 287867c..6e3ac48 100644 --- a/README +++ b/README @@ -67,5 +67,6 @@ AUTHOR Tatsuhiko Miyagawa SEE ALSO - Plack, + Plack, , + diff --git a/lib/Plack/Middleware/Deflater.pm b/lib/Plack/Middleware/Deflater.pm index ad37164..8c944f9 100644 --- a/lib/Plack/Middleware/Deflater.pm +++ b/lib/Plack/Middleware/Deflater.pm @@ -122,23 +122,7 @@ Plack::Middleware::Deflater - Compress response body with Gzip or Deflate use Plack::Builder; builder { - enable sub { - my $app = shift; - sub { - my $env = shift; - my $ua = $env->{HTTP_USER_AGENT} || ''; - # Netscape has some problem - $env->{"psgix.compress-only-text/html"} = 1 if $ua =~ m!^Mozilla/4!; - # Netscape 4.06-4.08 have some more problems - $env->{"psgix.no-compress"} = 1 if $ua =~ m!^Mozilla/4\.0[678]!; - # MSIE (7|8) masquerades as Netscape, but it is fine - if ( $ua =~ m!\bMSIE (?:7|8)! ) { - $env->{"psgix.no-compress"} = 0; - $env->{"psgix.compress-only-text/html"} = 0; - } - $app->($env); - } - }; + enable 'Deflater::Compat'; # For browser compatibility enable "Deflater", content_type => ['text/css','text/html','text/javascript','application/javascript'], vary_user_agent => 1; @@ -200,6 +184,6 @@ Tatsuhiko Miyagawa =head1 SEE ALSO -L, L +L, L, L =cut diff --git a/lib/Plack/Middleware/Deflater/Compat.pm b/lib/Plack/Middleware/Deflater/Compat.pm new file mode 100644 index 0000000..6877fca --- /dev/null +++ b/lib/Plack/Middleware/Deflater/Compat.pm @@ -0,0 +1,22 @@ +package Plack::Middleware::Deflater::Compat; +use strict; +use parent qw(Plack::Middleware); +use Plack::Util; + +sub call { + my($self, $env) = @_; + + my $ua = $env->{HTTP_USER_AGENT} || ''; + # Netscape has some problem + $env->{"psgix.compress-only-text/html"} = 1 if $ua =~ m!^Mozilla/4!; + # Netscape 4.06-4.08 have some more problems + $env->{"psgix.no-compress"} = 1 if $ua =~ m!^Mozilla/4\.0[678]!; + # MSIE (7|8) masquerades as Netscape, but it is fine + if ( $ua =~ m!\bMSIE (?:7|8)! ) { + $env->{"psgix.no-compress"} = 0; + $env->{"psgix.compress-only-text/html"} = 0; + } + return $self->app->($env); +} + +1;