commit dae2e40

default  ·  2023-08-19 07:59:58 +0000 UTC
parent 5c7b26b
history_add() now creates an etag.
3 files changed,  +11, -4
M data.c
M html.c
M snac.h
M data.c
+7, -1
 1@@ -1677,7 +1677,8 @@ double history_mtime(snac *snac, const char *id)
 2 }
 3 
 4 
 5-void history_add(snac *snac, const char *id, const char *content, int size)
 6+void history_add(snac *snac, const char *id, const char *content, int size,
 7+                    xs_str **etag)
 8 /* adds something to the history */
 9 {
10     xs *fn = _history_fn(snac, id);
11@@ -1686,6 +1687,11 @@ void history_add(snac *snac, const char *id, const char *content, int size)
12     if (fn && (f = fopen(fn, "w")) != NULL) {
13         fwrite(content, size, 1, f);
14         fclose(f);
15+
16+        if (etag) {
17+            double tm = mtime(fn);
18+            *etag = xs_fmt("W/\"snac-%.0lf\"", tm);
19+        }
20     }
21 }
22 
M html.c
+2, -2
 1@@ -1891,7 +1891,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
 2             status  = 200;
 3 
 4             if (save)
 5-                history_add(&snac, h, *body, *b_size);
 6+                history_add(&snac, h, *body, *b_size, etag);
 7         }
 8     }
 9     else
10@@ -1922,7 +1922,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
11                 status  = 200;
12 
13                 if (save)
14-                    history_add(&snac, "timeline.html_", *body, *b_size);
15+                    history_add(&snac, "timeline.html_", *body, *b_size, etag);
16             }
17         }
18     }
M snac.h
+2, -1
 1@@ -149,7 +149,8 @@ void static_put_meta(snac *snac, const char *id, const char *str);
 2 xs_str *static_get_meta(snac *snac, const char *id);
 3 
 4 double history_mtime(snac *snac, const char *id);
 5-void history_add(snac *snac, const char *id, const char *content, int size);
 6+void history_add(snac *snac, const char *id, const char *content, int size,
 7+                    xs_str **etag);
 8 int history_get(snac *snac, const char *id, xs_str **content, int *size,
 9                 const char *inm, xs_str **etag);
10 int history_del(snac *snac, const char *id);