summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/stat_cache.c2
-rwxr-xr-xtests/LightyTest.pm3
-rw-r--r--tests/Makefile.am5
-rwxr-xr-xtests/cachable.t112
4 files changed, 121 insertions, 1 deletions
diff --git a/src/stat_cache.c b/src/stat_cache.c
index 4100d0b5..a790e816 100644
--- a/src/stat_cache.c
+++ b/src/stat_cache.c
@@ -595,6 +595,8 @@ handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_
stat_cache_attr_get(sce->content_type, name->ptr);
}
#endif
+ } else if (S_ISDIR(st.st_mode)) {
+ etag_create(sce->etag, &(sce->st));
}
#ifdef HAVE_FAM_H
diff --git a/tests/LightyTest.pm b/tests/LightyTest.pm
index 81f92922..49d2175b 100755
--- a/tests/LightyTest.pm
+++ b/tests/LightyTest.pm
@@ -195,6 +195,9 @@ sub handle_http {
}
}
+ $t->{etag} = $resp_hdr{'etag'};
+ $t->{date} = $resp_hdr{'date'};
+
# check length
if (defined $resp_hdr{"content-length"}) {
$resp_body = substr($lines, 0, $resp_hdr{"content-length"});
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d4a9b109..584d9c98 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,7 +42,10 @@ CONFS=fastcgi-10.conf \
request.t \
mod-ssi.t \
LightyTest.pm \
- mod-setenv.t
+ mod-setenv.t \
+ lowercase.t \
+ lowercase.conf \
+ cachable.t
TESTS_ENVIRONMENT=$(srcdir)/wrapper.sh $(srcdir) $(top_builddir)
diff --git a/tests/cachable.t b/tests/cachable.t
new file mode 100755
index 00000000..74d9a4b1
--- /dev/null
+++ b/tests/cachable.t
@@ -0,0 +1,112 @@
+#!/usr/bin/env perl
+BEGIN {
+ # add current source dir to the include-path
+ # we need this for make distcheck
+ (my $srcdir = $0) =~ s#/[^/]+$#/#;
+ unshift @INC, $srcdir;
+}
+
+use strict;
+use IO::Socket;
+use Test::More tests => 12;
+use LightyTest;
+
+my $tf = LightyTest->new();
+my $t;
+
+$tf->{CONFIGFILE} = 'lighttpd.conf';
+
+ok($tf->start_proc == 0, "Starting lighttpd") or die();
+
+## check if If-Modified-Since, If-None-Match works
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+Last-Modified' => ''} ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - old If-Modified-Since, comment');
+
+my $now = $t->{date};
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-Modified-Since: $now
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-Modified-Since: $now; foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - new If-Modified-Since, comment');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-None-Match: foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200, '+ETag' => ''} ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
+
+my $etag = $t->{etag};
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-None-Match: $etag
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - old If-None-Match');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-None-Match: $etag
+If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + old Last-Modified');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-None-Match: $etag
+If-Modified-Since: $now; foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 304 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - ETag, Last-Modified + comment');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-None-Match: Foo
+If-Modified-Since: Sun, 01 Jan 1970 00:00:01 GMT; foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 200 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - old ETAG + old Last-Modified');
+
+$t->{REQUEST} = ( <<EOF
+GET / HTTP/1.0
+If-None-Match: $etag
+If-Modified-Since: $now foo
+EOF
+ );
+$t->{RESPONSE} = [ { 'HTTP-Protocol' => 'HTTP/1.0', 'HTTP-Status' => 412 } ];
+ok($tf->handle_http($t) == 0, 'Conditional GET - ETag + Last-Modified + overlong timestamp');
+
+ok($tf->stop_proc == 0, "Stopping lighttpd");
+