File: conditionalget.t

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (62 lines) | stat: -rw-r--r-- 2,185 bytes parent folder | download | duplicates (5)
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
58
59
60
61
62
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};
}