drain backend socket/pipe bufs upon FDEVENT_HUP
[lighttpd.git] / tests / core-404-handler.t
bloba7259ae7a4c4a806b3c0c03d2e7c620cad6f175a
1 #!/usr/bin/env perl
3 # combinations we have to test:
4 # plain 404 case
5 # 404-handler -> static file (verify content)
6 # 404-handler -> fastcgi
7 # returning 200
8 # returning 302 + Location
9 # returning 404
10 # returning no status -> 200
12 BEGIN {
13 # add current source dir to the include-path
14 # we need this for make distcheck
15 (my $srcdir = $0) =~ s,/[^/]+$,/,;
16 unshift @INC, $srcdir;
19 use strict;
20 use IO::Socket;
21 use Test::More tests => 9;
22 use LightyTest;
24 my $tf = LightyTest->new();
25 my $t;
26 $tf->{CONFIGFILE} = '404-handler.conf';
28 ok($tf->start_proc == 0, "Starting lighttpd") or die();
30 $t->{REQUEST} = ( <<EOF
31 GET /static/notfound HTTP/1.0
32 EOF
34 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "static not found\n" } ];
35 ok($tf->handle_http($t) == 0, '404 handler => static');
40 $t->{REQUEST} = ( <<EOF
41 GET /dynamic/200/notfound HTTP/1.0
42 EOF
44 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
45 ok($tf->handle_http($t) == 0, '404 handler => dynamic(200)');
47 $t->{REQUEST} = ( <<EOF
48 GET /dynamic/302/notfound HTTP/1.0
49 EOF
51 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 302, 'Location' => "http://www.example.org/" } ];
52 ok($tf->handle_http($t) == 0, '404 handler => dynamic(302)');
54 $t->{REQUEST} = ( <<EOF
55 GET /dynamic/404/notfound HTTP/1.0
56 EOF
58 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "Not found here\n" } ];
59 ok($tf->handle_http($t) == 0, '404 handler => dynamic(404)');
61 $t->{REQUEST} = ( <<EOF
62 GET /dynamic/redirect_status/ HTTP/1.0
63 EOF
65 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "REDIRECT_STATUS\n" } ];
66 ok($tf->handle_http($t) == 0, 'error handler => dynamic(REDIRECT_STATUS)');
68 $t->{REQUEST} = ( <<EOF
69 GET /dynamic/nostatus/notfound HTTP/1.0
70 EOF
72 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'HTTP-Content' => "found here\n" } ];
73 ok($tf->handle_http($t) == 0, '404 handler => dynamic(nostatus)');
75 $t->{REQUEST} = ( <<EOF
76 GET /send404.pl HTTP/1.0
77 EOF
79 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404, 'HTTP-Content' => "send404\n" } ];
80 ok($tf->handle_http($t) == 0, '404 generated by CGI should stay 404');
82 ok($tf->stop_proc == 0, "Stopping lighttpd");