/
deflater.t
35 lines (30 loc) · 1.01 KB
/
deflater.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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::Test;
use Plack::Middleware::Deflater;
$Plack::Test::Impl = "Server";
my @app = (
sub { [ 200, [], [ 'Hello World' ] ] },
sub { [ 200, [], [ 'Hello ', 'World' ] ] },
sub { [ 200, [], [ 'Hello ', '', 'World' ] ] },
sub { [ 200, [], io_from_array [ 'Hello World' ] ] },
sub { [ 200, [], io_from_array [ 'Hello', ' World' ] ] },
sub { [ 200, [], io_from_array [ 'Hello', '', ' World' ] ] },
);
my $app = sub { (shift @app)->(@_) };
test_psgi app => Plack::Middleware::Deflater->wrap($app), client => sub {
my $cb = shift;
no warnings;
local *HTTP::Request::decodable = sub { wantarray ? ('gzip') : 'gzip' };
for (0..$#app) {
my $req = GET "http://localhost/";
$req->accept_decodable;
my $res = $cb->($req);
is $res->decoded_content, 'Hello World';
is $res->content_encoding, 'gzip';
}
};
done_testing;