[mod_wstunnel] fix ping-interval for big-endian (fixes #2944)
[lighttpd.git] / tests / cachable.t
blobd0790e0ec593a61d1f05392ef8948da9998870e2
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 ok($tf->start_proc == 0, "Starting lighttpd") or die();
19 ## check if If-Modified-Since, If-None-Match works
21 $t->{REQUEST} = ( <<EOF
22 GET / HTTP/1.0
23 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT
24 EOF
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
30 GET / HTTP/1.0
31 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
32 EOF
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');
37 my $now = $t->{date};
39 $t->{REQUEST} = ( <<EOF
40 GET / HTTP/1.0
41 If-Modified-Since: $now
42 EOF
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
48 GET / HTTP/1.0
49 If-Modified-Since: $now; foo
50 EOF
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
56 GET / HTTP/1.0
57 If-None-Match: foo
58 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
66 GET / HTTP/1.0
67 If-None-Match: $etag
68 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
74 GET / HTTP/1.0
75 If-None-Match: $etag
76 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
77 EOF
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
83 GET / HTTP/1.0
84 If-None-Match: $etag
85 If-Modified-Since: $now; foo
86 EOF
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
92 GET / HTTP/1.0
93 If-None-Match: Foo
94 If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
95 EOF
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
101 GET / HTTP/1.0
102 If-None-Match: $etag
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
110 GET / HTTP/1.0
111 If-None-Match: $etag
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');
118 ###############
120 ok($etag =~ /^\"(.*)\"$/, "The server must quote ETags");
122 $t->{REQUEST} = ( <<EOF
123 GET / HTTP/1.0
124 If-None-Match: $1
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
132 GET / HTTP/1.0
133 If-None-Match: $1
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
140 GET / HTTP/1.0
141 If-None-Match: *
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
148 GET / HTTP/1.0
149 If-None-Match: "*"
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');
155 TODO: {
156 local $TODO = "weak etags not allowed yet";
157 $t->{REQUEST} = ( <<EOF
158 GET / HTTP/1.0
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
167 GET / HTTP/1.0
168 If-None-Match: W/$etag
169 Range: bytes=0-0
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
176 GET / HTTP/1.0
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
184 GET / HTTP/1.0
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');
191 TODO: {
192 local $TODO = "weak etags not allowed yet";
193 $t->{REQUEST} = ( <<EOF
194 GET / HTTP/1.0
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
203 GET / HTTP/1.0
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
211 GET / HTTP/1.0
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");