From 2cc551b8d2ccd35f7e58cff99a688d3e77489129 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 19 May 2022 18:11:53 +0200 Subject: htgen-cyberlocker: add if_modified_since logic --- .../simple/htgen-cyberlocker/src/htgen-cyberlocker | 23 ++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker b/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker index 5ca0ddd3e..d04b4b1f0 100644 --- a/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker +++ b/krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker @@ -5,6 +5,13 @@ emptyok_response() {( printf '\r\n' )} +not_modifed_response() {( + printf "HTTP/1.1 304 Not Modified\r\n" + printf 'Connection: close\r\n' + printf 'Server: %s\r\n' "$Server" + printf '\r\n' +)} + delete_response() { jq -n -r \ --arg server "$Server" \ @@ -74,8 +81,20 @@ case "$Method $path" in 'GET /'*) item=$STATEDIR/items/$(echo "$path" | jq -rR @uri) if [ -e "$item" ]; then - file_response "$item" - exit + if [ -z ${req_if_modified_since+x} ]; then + file_response "$item" + exit + else + age_file=$(date +%s -r "$item") + age_header=$(date +%s --date="$req_if_modified_since") + if [ "$age_file" -lt "$age_header" ]; then + not_modifed_response + exit + else + file_response "$item" + exit + fi + fi fi ;; 'DELETE /'*) -- cgit v1.2.3