summaryrefslogtreecommitdiff
path: root/src/libtipidee/tipidee_response_header_lastmodified.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-09-21 02:18:35 +0000
committerLaurent Bercot <ska@appnovation.com>2023-09-21 02:18:35 +0000
commit3d334dca671898241732dbc0ef6838b768308da7 (patch)
tree0cac6b60ea1356455fef2553e41105f3c68bce9d /src/libtipidee/tipidee_response_header_lastmodified.c
parent6be5496f8a5660875c5f45f915210f69496d231b (diff)
downloadtipidee-3d334dca671898241732dbc0ef6838b768308da7.tar.xz
Implement If-Modified-Since
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libtipidee/tipidee_response_header_lastmodified.c')
-rw-r--r--src/libtipidee/tipidee_response_header_lastmodified.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/libtipidee/tipidee_response_header_lastmodified.c b/src/libtipidee/tipidee_response_header_lastmodified.c
new file mode 100644
index 0000000..3b3caa6
--- /dev/null
+++ b/src/libtipidee/tipidee_response_header_lastmodified.c
@@ -0,0 +1,24 @@
+/* ISC license. */
+
+#include <skalibs/bsdsnowflake.h>
+
+#include <sys/stat.h>
+#include <errno.h>
+#include <string.h>
+
+#include <tipidee/response.h>
+
+size_t tipidee_response_header_lastmodified (char *s, size_t max, struct stat const *st)
+{
+ tain t ;
+ size_t l ;
+ if (max < 17) return (errno = ENOBUFS, 0) ;
+ if (!tain_from_timespec(&t, &st->st_mtim)) return 0 ;
+ memcpy(s, "Last-Modified: ", 15) ;
+ l = tipidee_response_header_date_fmt(s + 15, max - 15, &t) ;
+ if (!l) return 0 ;
+ if (l + 17 > max) return (errno = ENOBUFS, 0) ;
+ l += 15 ;
+ s[l++] = '\r' ; s[l++] = '\n' ;
+ return l ;
+}