diff options
author | lassulus <lassulus@lassul.us> | 2022-05-19 18:11:53 +0200 |
---|---|---|
committer | lassulus <lassulus@lassul.us> | 2022-05-19 18:11:53 +0200 |
commit | 2cc551b8d2ccd35f7e58cff99a688d3e77489129 (patch) | |
tree | 4834fe58fa35cf2a9b6219b64cc702567f704925 | |
parent | ca1621c17f867d006c4c394b3be046d42a6c5c7d (diff) |
htgen-cyberlocker: add if_modified_since logic
-rw-r--r-- | krebs/5pkgs/simple/htgen-cyberlocker/src/htgen-cyberlocker | 23 |
1 files 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 /'*) |