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 63 64
|
# please insert nothing before this line: -*- mode: cperl; cperl-indent-level: 4; cperl-continued-statement-offset: 4; indent-tabs-mode: nil -*-
use strict;
use warnings FATAL => 'all';
use Apache::Test;
use Apache::TestUtil;
use Apache::TestRequest;
use File::Spec::Functions qw(catfile);
my $url = '/TestAPI__sendfile';
my $file = catfile Apache::Test::vars('serverroot'),
'response/TestAPI/sendfile.pm';
my $contents;
open my $fh, $file or die "can't open $file: $!";
# need binmode on Win32 so as not to strip \r, which
# are included when sending with sendfile().
binmode $fh;
{ local $/; $contents = <$fh>; }
close $fh;
plan tests => 7, need 'HTML::HeadParser';
{
my $header = "This is a header\n";
my $footer = "This is a footer\n";
my $received = GET_BODY "$url?withwrapper";
my $expected = join '', $header, $contents, $footer;
#t_debug($received);
ok $received && $received eq $expected;
}
{
my $received = GET_BODY "$url?offset";
my $expected = substr $contents, 3;
#t_debug($received);
ok $received && $received eq $expected;
}
{
my $received = GET_BODY "$url?len";
my $expected = substr $contents, 3, 50;
#t_debug($received);
ok $received && $received eq $expected;
}
{
# rc is checked and handled by the code
my $res = GET "$url?noexist.txt";
ok t_cmp($res->code, 500, "failed sendfile");
#t_debug($res->content);
ok $res->content =~ /an internal error/;
}
{
# rc is not checked in this one, testing the exception throwing
my $res = GET "$url?noexist-n-nocheck.txt";
ok t_cmp($res->code, 500, "failed sendfile");
#t_debug($res->content);
ok $res->content =~ /an internal error/;
}
|