3 # add current source dir to the include-path
4 # we need this for make distcheck
5 (my $srcdir = $0) =~ s
,/[^/]+$,/,;
11 use Test
::More tests
=> 14;
14 my $tf = LightyTest
->new();
17 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
19 ## Low-Level Response-Header Parsing - HTTP/1.1
21 $t->{REQUEST
} = ( <<EOF
27 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 200, '+Date' => '' } ];
28 ok
($tf->handle_http($t) == 0, 'Date header');
30 $t->{REQUEST
} = ( <<EOF
34 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.1', 'HTTP-Status' => 400, 'Connection' => 'close' } ];
35 ok
($tf->handle_http($t) == 0, 'Host missing');
37 $t->{REQUEST
} = ( <<EOF
41 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => '' } ];
42 ok
($tf->handle_http($t) == 0, 'ETag is set');
44 $t->{REQUEST
} = ( <<EOF
48 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'ETag' => '/^".+"$/' } ];
49 ok
($tf->handle_http($t) == 0, 'ETag has quotes');
53 ## Low-Level Response-Header Parsing - Content-Length
56 $t->{REQUEST
} = ( <<EOF
57 GET /12345.html HTTP/1.0
61 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
62 ok
($tf->handle_http($t) == 0, 'Content-Length for text/html');
64 $t->{REQUEST
} = ( <<EOF
65 GET /12345.txt HTTP/1.0
69 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
70 ok
($tf->handle_http($t) == 0, 'Content-Length for text/plain');
73 ## Low-Level Response-Header Parsing - Location
75 $t->{REQUEST
} = ( <<EOF
76 GET /dummydir HTTP/1.0
79 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME
}.':'.$tf->{PORT
}.'/dummydir/' } ];
80 ok
($tf->handle_http($t) == 0, 'internal redirect in directory');
82 $t->{REQUEST
} = ( <<EOF
83 GET /dummydir?foo HTTP/1.0
86 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME
}.':'.$tf->{PORT
}.'/dummydir/?foo' } ];
87 ok
($tf->handle_http($t) == 0, 'internal redirect in directory + querystring');
89 $t->{REQUEST
} = ( <<EOF
90 GET /~test%20ä_ HTTP/1.0
93 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME
}.':'.$tf->{PORT
}.'/~test%20%C3%A4_/' } ];
94 ok
($tf->handle_http($t) == 0, 'internal redirect in directory with special characters');
96 $t->{REQUEST
} = ( <<EOF
97 GET /~test%20ä_?foo HTTP/1.0
100 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 301, 'Location' => 'http://'.$tf->{HOSTNAME
}.':'.$tf->{PORT
}.'/~test%20%C3%A4_/?foo' } ];
101 ok
($tf->handle_http($t) == 0, 'internal redirect in directory with special characters + querystring');
105 $t->{REQUEST
} = ( <<EOF
106 GET /12345.txt HTTP/1.0
107 Host: no-simple.example.org
110 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, 'Content-Length' => '6' } ];
111 ok
($tf->handle_http($t) == 0, 'disabling simple-vhost via conditionals');
113 $t->{REQUEST
} = ( <<EOF
114 GET /12345.txt HTTP/1.0
115 Host: simple.example.org
118 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 404 } ];
119 ok
($tf->handle_http($t) == 0, 'simple-vhost via conditionals');
121 ok
($tf->stop_proc == 0, "Stopping lighttpd");