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
=> 25;
14 my $tf = LightyTest
->new();
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
25 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT
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
33 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
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');
41 $t->{REQUEST
} = ( <<EOF
43 If-Modified-Since: $now
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
51 If-Modified-Since: $now; foo
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
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
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
78 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
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
87 If-Modified-Since: $now; foo
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
96 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
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
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
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');
122 ok
($etag =~ /^\"(.*)\"$/, "The server must quote ETags");
124 $t->{REQUEST
} = ( <<EOF
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
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
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
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');
158 local $TODO = "weak etags not allowed yet";
159 $t->{REQUEST
} = ( <<EOF
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
170 If-None-Match: W/$etag
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
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
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');
194 local $TODO = "weak etags not allowed yet";
195 $t->{REQUEST
} = ( <<EOF
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
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
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");