ignore return value from fcntl() FD_CLOEXEC
[lighttpd.git] / tests / cachable.t
blobcd47eb2dfd309707c9378951ee2e560763f54815
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 => 25;
12 use LightyTest;
14 my $tf = LightyTest->new();
15 my $t;
17 $tf->{CONFIGFILE} = 'lighttpd.conf';
19 ok($tf->start_proc == 0, "Starting lighttpd") or die();
21 ## check if If-Modified-Since, If-None-Match works
23 $t->{REQUEST} = ( <<EOF
24 GET / HTTP/1.0
25 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT
26 EOF
28 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
29 ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since');
31 $t->{REQUEST} = ( <<EOF
32 GET / HTTP/1.0
33 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
34 EOF
36 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Last-Modified' => ''} ];
37 ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since, comment');
39 my $now = $t->{date};
41 $t->{REQUEST} = ( <<EOF
42 GET / HTTP/1.0
43 If-Modified-Since: $now
44 EOF
46 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
47 ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since');
49 $t->{REQUEST} = ( <<EOF
50 GET / HTTP/1.0
51 If-Modified-Since: $now; foo
52 EOF
54 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
55 ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since, comment');
57 $t->{REQUEST} = ( <<EOF
58 GET / HTTP/1.0
59 If-None-Match: foo
60 EOF
62 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => ''} ];
63 ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
65 my $etag = $t->{etag};
67 $t->{REQUEST} = ( <<EOF
68 GET / HTTP/1.0
69 If-None-Match: $etag
70 EOF
72 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
73 ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
75 $t->{REQUEST} = ( <<EOF
76 GET / HTTP/1.0
77 If-None-Match: $etag
78 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
79 EOF
81 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
82 ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + old Last-Modified (which should be ignored)');
84 $t->{REQUEST} = ( <<EOF
85 GET / HTTP/1.0
86 If-None-Match: $etag
87 If-Modified-Since: $now; foo
88 EOF
90 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
91 ok($tf->handle_http($t) == 0, 'Conditional GET - ETag, Last-Modified + comment (which should be ignored)');
93 $t->{REQUEST} = ( <<EOF
94 GET / HTTP/1.0
95 If-None-Match: Foo
96 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
97 EOF
99 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
100 ok($tf->handle_http($t) == 0, 'Conditional GET - old ETAG + old Last-Modified');
102 $t->{REQUEST} = ( <<EOF
103 GET / HTTP/1.0
104 If-None-Match: $etag
105 If-Modified-Since: $now foo
108 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
109 ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + Last-Modified + overlong timestamp (which should be ignored)');
111 $t->{REQUEST} = ( <<EOF
112 GET / HTTP/1.0
113 If-None-Match: $etag
114 Host: etag.example.org
117 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
118 ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + disabled etags on server side');
120 ###############
122 ok($etag =~ /^\"(.*)\"$/, "The server must quote ETags");
124 $t->{REQUEST} = ( <<EOF
125 GET / HTTP/1.0
126 If-None-Match: $1
129 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
130 ok($tf->handle_http($t) == 0, 'The client must send a quoted ETag');
132 $etag =~ /^(\".*)\"$/;
133 $t->{REQUEST} = ( <<EOF
134 GET / HTTP/1.0
135 If-None-Match: $1
138 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
139 ok($tf->handle_http($t) == 0, 'The ETag must be surrounded by quotes');
141 $t->{REQUEST} = ( <<EOF
142 GET / HTTP/1.0
143 If-None-Match: *
146 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
147 ok($tf->handle_http($t) == 0, 'An unquoted star matches any ETag');
149 $t->{REQUEST} = ( <<EOF
150 GET / HTTP/1.0
151 If-None-Match: "*"
154 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
155 ok($tf->handle_http($t) == 0, 'A quoted star is just a regular ETag');
157 TODO: {
158 local $TODO = "weak etags not allowed yet";
159 $t->{REQUEST} = ( <<EOF
160 GET / HTTP/1.0
161 If-None-Match: W/$etag
164 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
165 ok($tf->handle_http($t) == 0, 'A weak etag matches like a regular ETag for HEAD and GET');
168 $t->{REQUEST} = ( <<EOF
169 GET / HTTP/1.0
170 If-None-Match: W/$etag
171 Range: bytes=0-0
174 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '<' } ];
175 ok($tf->handle_http($t) == 0, 'A weak etag does not match for ranged requests');
177 $t->{REQUEST} = ( <<EOF
178 GET / HTTP/1.0
179 If-None-Match: W/"12345"
182 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
183 ok($tf->handle_http($t) == 0, 'However, a weak ETag is not *');
185 $t->{REQUEST} = ( <<EOF
186 GET / HTTP/1.0
187 If-None-Match: "12345", $etag
190 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
191 ok($tf->handle_http($t) == 0, 'Client sent a list of ETags, the second matches');
193 TODO: {
194 local $TODO = "weak etags not allowed yet";
195 $t->{REQUEST} = ( <<EOF
196 GET / HTTP/1.0
197 If-None-Match: "12345", W/$etag
200 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
201 ok($tf->handle_http($t) == 0, 'The second provided ETag matches weakly');
204 $t->{REQUEST} = ( <<EOF
205 GET / HTTP/1.0
206 If-None-Match: "12345",, ,, , $etag
209 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
210 ok($tf->handle_http($t) == 0, 'Broken client did get around to sending good data');
212 $t->{REQUEST} = ( <<EOF
213 GET / HTTP/1.0
214 If-None-Match: "1234", $etag, "brokentrailing
217 $t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
218 ok($tf->handle_http($t) == 0, 'Bad syntax *after* a matching ETag doesn\'t matter');
220 ok($tf->stop_proc == 0, "Stopping lighttpd");