Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@ AUTHOR
Tatsuhiko Miyagawa

SEE ALSO
Plack, <http://httpd.apache.org/docs/2.2/en/mod/mod_deflate.html>
Plack, <http://httpd.apache.org/docs/2.2/en/mod/mod_deflate.html>,
<https://github.com/miyagawa/Plack-Middleware-Deflater>

20 changes: 2 additions & 18 deletions lib/Plack/Middleware/Deflater.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -200,6 +184,6 @@ Tatsuhiko Miyagawa

=head1 SEE ALSO

L<Plack>, L<http://httpd.apache.org/docs/2.2/en/mod/mod_deflate.html>
L<Plack>, L<http://httpd.apache.org/docs/2.2/en/mod/mod_deflate.html>, L<https://github.com/miyagawa/Plack-Middleware-Deflater>

=cut
22 changes: 22 additions & 0 deletions lib/Plack/Middleware/Deflater/Compat.pm
Original file line number Diff line number Diff line change
@@ -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;