history_add() now creates an etag.

This commit is contained in:
default 2023-08-19 09:59:58 +02:00
parent 5c7b26bcdc
commit dae2e406d6
3 changed files with 11 additions and 4 deletions

8
data.c
View file

@ -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 */ /* adds something to the history */
{ {
xs *fn = _history_fn(snac, id); 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) { if (fn && (f = fopen(fn, "w")) != NULL) {
fwrite(content, size, 1, f); fwrite(content, size, 1, f);
fclose(f); fclose(f);
if (etag) {
double tm = mtime(fn);
*etag = xs_fmt("W/\"snac-%.0lf\"", tm);
}
} }
} }

4
html.c
View file

@ -1891,7 +1891,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
status = 200; status = 200;
if (save) if (save)
history_add(&snac, h, *body, *b_size); history_add(&snac, h, *body, *b_size, etag);
} }
} }
else else
@ -1922,7 +1922,7 @@ int html_get_handler(const xs_dict *req, const char *q_path,
status = 200; status = 200;
if (save) if (save)
history_add(&snac, "timeline.html_", *body, *b_size); history_add(&snac, "timeline.html_", *body, *b_size, etag);
} }
} }
} }

3
snac.h
View file

@ -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); xs_str *static_get_meta(snac *snac, const char *id);
double history_mtime(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, int history_get(snac *snac, const char *id, xs_str **content, int *size,
const char *inm, xs_str **etag); const char *inm, xs_str **etag);
int history_del(snac *snac, const char *id); int history_del(snac *snac, const char *id);