/
conditionalget.t
62 lines (54 loc) · 2.13 KB
/
conditionalget.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use strict;
use warnings;
use Plack::Builder;
use Test::More;
my @tests = (
{
app => sub { [ 200, [ 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
env => { REQUEST_METHOD => 'GET' },
status => 200,
headers => [ 'Content-Type', 'text/plain' ],
},
{
app => sub { [ 200, [ 'ETag' => 'Foo', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
env => { REQUEST_METHOD => "GET", HTTP_IF_NONE_MATCH => "Foo" },
status => 304,
headers => [ ETag => 'Foo' ],
},
{
app => sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => "Wed, 23 Sep 2009 13:36:33 GMT" },
status => 304,
headers => [ "Last-Modified" => "Wed, 23 Sep 2009 13:36:33 GMT" ],
},
{
app => sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => "Wed, 23 Sep 2009 13:36:32 GMT" },
status => 200,
headers => [
"Last-Modified", "Wed, 23 Sep 2009 13:36:33 GMT", "Content-Type", "text/plain",
],
},
{
app => sub { [ 200, [ 'Last-Modified' => 'Wed, 23 Sep 2009 13:36:33 GMT', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
env => { REQUEST_METHOD => "GET", HTTP_IF_MODIFIED_SINCE => "Wed, 23 Sep 2009 13:36:33 GMT; length=2" },
status => 304,
headers => [ "Last-Modified", "Wed, 23 Sep 2009 13:36:33 GMT" ],
},
{
app => sub { [ 200, [ 'ETag' => 'Foo', 'Content-Type' => 'text/plain' ], [ 'OK' ] ] },
env => { REQUEST_METHOD => "POST", HTTP_IF_NONE_MATCH => "Foo" },
status => 200,
headers => [ ETag => "Foo", "Content-Type" => "text/plain" ],
}
);
plan tests => 2*@tests;
for my $block (@tests) {
my $handler = builder {
enable "Plack::Middleware::ConditionalGET";
$block->{app};
};
my $res = $handler->($block->{env});
is $res->[0], $block->{status};
is_deeply $res->[1], $block->{headers};
}