forked from plack/Plack-Middleware-Deflater
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Masahiro Nagano
committed
Feb 1, 2011
1 parent
3b5c589
commit efed57f
Showing
2 changed files
with
111 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use strict; | ||
use Test::More; | ||
use Test::Requires qw(IO::Handle::Util); | ||
use IO::Handle::Util qw(:io_from); | ||
use HTTP::Request::Common; | ||
use Plack::Builder; | ||
use Plack::Test; | ||
use Plack::Middleware::Deflater; | ||
$Plack::Test::Impl = "Server"; | ||
|
||
## content_type nomatch, no vary sets. | ||
my $app = builder { | ||
enable sub { | ||
my $cb = shift; | ||
sub { | ||
my $env = shift; | ||
$env->{"psgix.no-gzip"} = 1; | ||
$cb->($env); | ||
} | ||
}; | ||
enable 'Deflater', content_type => 'text/html', vary_user_agent => 1; | ||
sub { [200, [ 'Content-Type' => 'text/html' ], [ "Hello World" ]] } | ||
}; | ||
|
||
test_psgi | ||
app => $app, | ||
client => sub { | ||
my $cb = shift; | ||
my $req = HTTP::Request->new(GET => "http://localhost/"); | ||
my $res = $cb->($req); | ||
is $res->decoded_content, 'Hello World'; | ||
isnt $res->content_encoding, 'gzip'; | ||
like $res->header('Vary') || '', qr/Accept-Encoding/; | ||
like $res->header('Vary') || '', qr/User-Agent/; | ||
}; | ||
|
||
|
||
my $app2 = builder { | ||
enable sub { | ||
my $cb = shift; | ||
sub { | ||
my $env = shift; | ||
$env->{"psgix.gzip-only-text/html"} = 1; | ||
$cb->($env); | ||
} | ||
}; | ||
enable 'Deflater', content_type => 'text/plain', vary_user_agent => 1; | ||
sub { [200, [ 'Content-Type' => 'text/plain' ], [ "Hello World" ]] } | ||
}; | ||
|
||
test_psgi | ||
app => $app2, | ||
client => sub { | ||
my $cb = shift; | ||
my $req = HTTP::Request->new(GET => "http://localhost/"); | ||
my $res = $cb->($req); | ||
is $res->decoded_content, 'Hello World'; | ||
isnt $res->content_encoding, 'gzip'; | ||
like $res->header('Vary') || '', qr/Accept-Encoding/; | ||
like $res->header('Vary') || '', qr/User-Agent/; | ||
}; | ||
|
||
|
||
done_testing; | ||
|