File: streaming.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 (36 lines) | stat: -rw-r--r-- 1,160 bytes parent folder | download | duplicates (8)
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
use Plack::Test;
use Test::More;

use Plack::App::Cascade;
use HTTP::Request::Common;

my $cascade = Plack::App::Cascade->new;
$cascade->add( sub { return sub { my $respond = shift; $respond->([ 404, [], [ "Duh" ] ]) } } );
$cascade->add( sub { return [ 403, [ 'Content-Type', 'text/plain' ], [ "Forbidden" ] ] } );
$cascade->add( sub { my $env = shift;
                     return sub {
                         my $r = shift;
                         if ($env->{PATH_INFO} eq '/') {
                             my $w = $r->([ 200, [ 'Content-Type', 'text/plain' ] ]);
                             $w->write("Hello");
                             $w->close;
                         } else {
                             $r->([ 404, [ 'Content-Type', 'text/plain' ], [ 'Custom 404 Page' ] ]);
                         }
                     } });

$cascade->catch([ 403, 404 ]);

test_psgi $cascade, sub {
    my $cb = shift;

    my $res = $cb->(GET "http://localhost/");
    is $res->code, 200;
    is $res->content, "Hello";

    $res = $cb->(GET "http://localhost/xyz");
    is $res->code, 404;
    is $res->content, 'Custom 404 Page';
};

done_testing;