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 ok
($tf->start_proc == 0, "Starting lighttpd") or die();
19 ## check if If-Modified-Since, If-None-Match works
21 $t->{REQUEST
} = ( <<EOF
23 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT
26 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
27 ok
($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since');
29 $t->{REQUEST
} = ( <<EOF
31 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
34 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Last-Modified' => ''} ];
35 ok
($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since, comment');
39 $t->{REQUEST
} = ( <<EOF
41 If-Modified-Since: $now
44 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
45 ok
($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since');
47 $t->{REQUEST
} = ( <<EOF
49 If-Modified-Since: $now; foo
52 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
53 ok
($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since, comment');
55 $t->{REQUEST
} = ( <<EOF
60 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => ''} ];
61 ok
($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
63 my $etag = $t->{etag
};
65 $t->{REQUEST
} = ( <<EOF
70 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
71 ok
($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
73 $t->{REQUEST
} = ( <<EOF
76 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
79 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
80 ok
($tf->handle_http($t) == 0, 'Conditional GET - ETag + old Last-Modified (which should be ignored)');
82 $t->{REQUEST
} = ( <<EOF
85 If-Modified-Since: $now; foo
88 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
89 ok
($tf->handle_http($t) == 0, 'Conditional GET - ETag, Last-Modified + comment (which should be ignored)');
91 $t->{REQUEST
} = ( <<EOF
94 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
97 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
98 ok
($tf->handle_http($t) == 0, 'Conditional GET - old ETAG + old Last-Modified');
100 $t->{REQUEST
} = ( <<EOF
103 If-Modified-Since: $now foo
106 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
107 ok
($tf->handle_http($t) == 0, 'Conditional GET - ETag + Last-Modified + overlong timestamp (which should be ignored)');
109 $t->{REQUEST
} = ( <<EOF
112 Host: etag.example.org
115 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
116 ok
($tf->handle_http($t) == 0, 'Conditional GET - ETag + disabled etags on server side');
120 ok
($etag =~ /^\"(.*)\"$/, "The server must quote ETags");
122 $t->{REQUEST
} = ( <<EOF
127 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
128 ok
($tf->handle_http($t) == 0, 'The client must send a quoted ETag');
130 $etag =~ /^(\".*)\"$/;
131 $t->{REQUEST
} = ( <<EOF
136 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
137 ok
($tf->handle_http($t) == 0, 'The ETag must be surrounded by quotes');
139 $t->{REQUEST
} = ( <<EOF
144 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
145 ok
($tf->handle_http($t) == 0, 'An unquoted star matches any ETag');
147 $t->{REQUEST
} = ( <<EOF
152 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
153 ok
($tf->handle_http($t) == 0, 'A quoted star is just a regular ETag');
156 local $TODO = "weak etags not allowed yet";
157 $t->{REQUEST
} = ( <<EOF
159 If-None-Match: W/$etag
162 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
163 ok
($tf->handle_http($t) == 0, 'A weak etag matches like a regular ETag for HEAD and GET');
166 $t->{REQUEST
} = ( <<EOF
168 If-None-Match: W/$etag
172 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '<' } ];
173 ok
($tf->handle_http($t) == 0, 'A weak etag does not match for ranged requests');
175 $t->{REQUEST
} = ( <<EOF
177 If-None-Match: W/"12345"
180 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
181 ok
($tf->handle_http($t) == 0, 'However, a weak ETag is not *');
183 $t->{REQUEST
} = ( <<EOF
185 If-None-Match: "12345", $etag
188 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
189 ok
($tf->handle_http($t) == 0, 'Client sent a list of ETags, the second matches');
192 local $TODO = "weak etags not allowed yet";
193 $t->{REQUEST
} = ( <<EOF
195 If-None-Match: "12345", W/$etag
198 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
199 ok
($tf->handle_http($t) == 0, 'The second provided ETag matches weakly');
202 $t->{REQUEST
} = ( <<EOF
204 If-None-Match: "12345",, ,, , $etag
207 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
208 ok
($tf->handle_http($t) == 0, 'Broken client did get around to sending good data');
210 $t->{REQUEST
} = ( <<EOF
212 If-None-Match: "1234", $etag, "brokentrailing
215 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
216 ok
($tf->handle_http($t) == 0, 'Bad syntax *after* a matching ETag doesn\'t matter');
218 ok
($tf->stop_proc == 0, "Stopping lighttpd");