From dae2e406d633ba32f2660100ef417ec13726765c Mon Sep 17 00:00:00 2001 From: default Date: Sat, 19 Aug 2023 09:59:58 +0200 Subject: [PATCH] history_add() now creates an etag. --- data.c | 8 +++++++- html.c | 4 ++-- snac.h | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/data.c b/data.c index 9c335be..bfe035e 100644 --- a/data.c +++ b/data.c @@ -1677,7 +1677,8 @@ double history_mtime(snac *snac, const char *id) } -void history_add(snac *snac, const char *id, const char *content, int size) +void history_add(snac *snac, const char *id, const char *content, int size, + xs_str **etag) /* adds something to the history */ { xs *fn = _history_fn(snac, id); @@ -1686,6 +1687,11 @@ void history_add(snac *snac, const char *id, const char *content, int size) if (fn && (f = fopen(fn, "w")) != NULL) { fwrite(content, size, 1, f); fclose(f); + + if (etag) { + double tm = mtime(fn); + *etag = xs_fmt("W/\"snac-%.0lf\"", tm); + } } } diff --git a/html.c b/html.c index 11c1918..2b690e9 100644 --- a/html.c +++ b/html.c @@ -1891,7 +1891,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, status = 200; if (save) - history_add(&snac, h, *body, *b_size); + history_add(&snac, h, *body, *b_size, etag); } } else @@ -1922,7 +1922,7 @@ int html_get_handler(const xs_dict *req, const char *q_path, status = 200; if (save) - history_add(&snac, "timeline.html_", *body, *b_size); + history_add(&snac, "timeline.html_", *body, *b_size, etag); } } } diff --git a/snac.h b/snac.h index 8df5fb4..547b8b0 100644 --- a/snac.h +++ b/snac.h @@ -149,7 +149,8 @@ void static_put_meta(snac *snac, const char *id, const char *str); xs_str *static_get_meta(snac *snac, const char *id); double history_mtime(snac *snac, const char *id); -void history_add(snac *snac, const char *id, const char *content, int size); +void history_add(snac *snac, const char *id, const char *content, int size, + xs_str **etag); int history_get(snac *snac, const char *id, xs_str **content, int *size, const char *inm, xs_str **etag); int history_del(snac *snac, const char *id);