Implement 304 Not Modified

This commit is contained in:
Vincent Riquer 2015-02-01 22:19:48 +01:00
parent a7c2b63dbe
commit b969488ac6
4 changed files with 37 additions and 25 deletions

View File

@ -24,11 +24,10 @@ do
done
read_query_string
send_headers <<-EOHead
content-type: text/xml
EOHead
cat <<-EOHTML
content-type: text/xml
Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

8
import
View File

@ -88,11 +88,11 @@ then
echo $'\nCache cleared!'
fi
else
cat <<-EOHTML
content-type: text/xml
Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
send_headers <<-EOHead
content-type: text/xml
EOHead
cat <<-EOHTML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

25
index
View File

@ -39,6 +39,11 @@ read_query_string
if [ -z "$graph" ]
then
send_headers <<-EOHead
content-type: application/xhtml+xml
refresh: 300
EOHead
readlast
medals
get_current_level
@ -54,14 +59,6 @@ then
title="IngRRD - $webuser [L$curlevel] - Overview"
fi
cat <<-EOHTML
content-type: application/xhtml+xml
Last-Modified: $(
LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' \
-d @$(rrdtool last ingress.rrd)
)
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '1 hour')
refresh: 10
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
@ -479,17 +476,11 @@ then
</body></html>
EOHTML
else
now=$(date +%s)
cat <<-EOHEAD
send_headers <<-EOHead
content-type: image/png
Last-Modified: $(
LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' \
-d @$(rrdtool last ingress.rrd)
)
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '1 hour')
EOHEAD
EOHead
now=$(date +%s)
if [[ $graph == AP ]]
then
thresholds=(

22
lib/send_headers Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash
send_headers() {
local timestamp do_exit header thisdate expiredate
read timestamp < <(stat -c %Y $0 "$rrdfile" lib/* |sort -r)
thisdate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d @$timestamp)
expiredate=$(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z' -d '+1 minute')
if [[ $thisdate == $HTTP_IF_MODIFIED_SINCE ]]
then
echo "Status: 304 Not Modified"
do_exit=1
fi
echo "Last-Modified: $thisdate"
echo "Expires: $expiredate"
echo "Cache-Control: must-revalidate, max-age=60"
while read header
do
echo "$header"
done
echo
(( do_exit )) && exit
}