- next is 1.4.56
[lighttpd.git] / tests / core-response.t
blob29aee6a484489f1983f5763e528bec333789e90b
1 #!/usr/bin/env perl
2 BEGIN {
3 # add current source dir to the include-path
4 # we need this for make distcheck
5 (my $srcdir = $0) =~ s,/[^/]+$,/,;
6 unshift @INC, $srcdir;
9 use strict;
10 use IO::Socket;
11 use Test::More tests => 14;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
17 ok($tf->start_proc == 0, "Starting lighttpd") or die();
19 ## Low-Level Response-Header Parsing - HTTP/1.1
21 $t->{REQUEST} = ( <<EOF
22 GET / HTTP/1.1
23 Host: www.example.org
24 Connection: close
25 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
31 GET / HTTP/1.1
32 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
38 GET / HTTP/1.0
39 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
45 GET / HTTP/1.0
46 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
58 Host: 123.example.org
59 EOF
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
66 Host: 123.example.org
67 EOF
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
77 EOF
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
84 EOF
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
91 EOF
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
98 EOF
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');
103 ## simple-vhost
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");