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 $t->{REQUEST
} = ( <<EOF
158 If-None-Match: W/$etag
161 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
162 ok
($tf->handle_http($t) == 0, 'A weak etag matches like a regular ETag for HEAD and GET');
165 $t->{REQUEST
} = ( <<EOF
167 If-None-Match: W/$etag
171 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 206, 'HTTP-Content' => '<' } ];
172 ok
($tf->handle_http($t) == 0, 'A weak etag does not match for ranged requests');
174 $t->{REQUEST
} = ( <<EOF
176 If-None-Match: W/"12345"
179 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
180 ok
($tf->handle_http($t) == 0, 'However, a weak ETag is not *');
182 $t->{REQUEST
} = ( <<EOF
184 If-None-Match: "12345", $etag
187 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
188 ok
($tf->handle_http($t) == 0, 'Client sent a list of ETags, the second matches');
191 $t->{REQUEST
} = ( <<EOF
193 If-None-Match: "12345", W/$etag
196 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
197 ok
($tf->handle_http($t) == 0, 'The second provided ETag matches weakly');
200 $t->{REQUEST
} = ( <<EOF
202 If-None-Match: "12345",, ,, , $etag
205 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
206 ok
($tf->handle_http($t) == 0, 'Broken client did get around to sending good data');
208 $t->{REQUEST
} = ( <<EOF
210 If-None-Match: "1234", $etag, "brokentrailing
213 $t->{RESPONSE
} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
214 ok
($tf->handle_http($t) == 0, 'Bad syntax *after* a matching ETag doesn\'t matter');
216 ok
($tf->stop_proc == 0, "Stopping lighttpd");