diff options
| -rwxr-xr-x | tests/t0022-error-page-headers.sh | 37 | ||||
| -rw-r--r-- | ui-shared.c | 2 |
2 files changed, 38 insertions, 1 deletions
diff --git a/tests/t0022-error-page-headers.sh b/tests/t0022-error-page-headers.sh new file mode 100755 index 0000000..51fbad8 --- /dev/null +++ b/tests/t0022-error-page-headers.sh @@ -0,0 +1,37 @@ +#!/bin/sh + +test_description='Check the Expires header on error pages' +. ./setup.sh + +# cgit_vprint_error_page() derives page.expires from cache-dynamic-ttl, which +# is a count of minutes, while page.expires is an absolute time. Checking the +# result needs no date arithmetic: a zero TTL has to reproduce Last-Modified +# exactly, and a non-zero one has to land somewhere else without falling back +# to the epoch. + +header_value() { + sed -n "s/^$1: //p" "$2" | tr -d '\r' +} + +test_expect_success 'a non-zero dynamic TTL expires the error page later' ' + cgit_url "bar/commit/&id=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" >output && + grep -q "Status: 404 Not found" output && + modified=$(header_value Last-Modified output) && + expires=$(header_value Expires output) && + test -n "$modified" && + test -n "$expires" && + test "$modified" != "$expires" && + case "$expires" in *1970*) return 1 ;; esac +' + +test_expect_success 'a zero dynamic TTL expires the error page immediately' ' + rm -rf cache && mkdir -p cache && + printf "cache-dynamic-ttl=0\n" >>cgitrc && + cgit_url "bar/commit/&id=deadbeefdeadbeefdeadbeefdeadbeefdeadbeef" >output && + modified=$(header_value Last-Modified output) && + expires=$(header_value Expires output) && + test -n "$modified" && + test "$modified" = "$expires" +' + +test_done diff --git a/ui-shared.c b/ui-shared.c index df52a9b..44794d8 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -896,7 +896,7 @@ void cgit_print_error_page(int code, const char *msg, const char *fmt, ...) void cgit_vprint_error_page(int code, const char *msg, const char *fmt, va_list ap) { - ctx.page.expires = ctx.cfg.cache_dynamic_ttl; + ctx.page.expires = ctx.page.modified + ctx.cfg.cache_dynamic_ttl * 60; ctx.page.status = code; ctx.page.statusmsg = msg; cgit_print_layout_start(); |
