From f66cfaec12b8b136c1f81ebac03cb665e55cbc6c Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 6 Nov 2024 12:41:54 -0500 Subject: [PATCH] http: Fix some caching issues. --- src/httpd.js.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/httpd.js.c b/src/httpd.js.c index 2278f0d8..78e22594 100644 --- a/src/httpd.js.c +++ b/src/httpd.js.c @@ -1222,6 +1222,7 @@ typedef struct _view_t const char** form_data; void* data; size_t size; + char etag[256]; bool not_modified; } view_t; @@ -1245,7 +1246,7 @@ static void _httpd_endpoint_view_work(tf_ssb_t* ssb, void* user_data) { view_t* view = user_data; tf_http_request_t* request = view->request; - char blob_id[256] = ""; + char blob_id[128] = ""; user_app_t* user_app = _parse_user_app_from_path(request->path, "/view"); if (user_app) @@ -1266,10 +1267,11 @@ static void _httpd_endpoint_view_work(tf_ssb_t* ssb, void* user_data) if (*blob_id) { + snprintf(view->etag, sizeof(view->etag), "\"%s\"", blob_id); const char* if_none_match = tf_http_request_get_header(request, "if-none-match"); char match[258]; snprintf(match, sizeof(match), "\"%s\"", blob_id); - if (if_none_match && strcmp(if_none_match, match)) + if (if_none_match && strcmp(if_none_match, match) == 0) { view->not_modified = true; } @@ -1298,6 +1300,8 @@ static void _httpd_endpoint_view_after_work(tf_ssb_t* ssb, int status, void* use "sandbox allow-downloads allow-top-navigation-by-user-activation", "Content-Type", view->data ? _httpd_mime_type_from_magic_bytes(view->data, view->size) : "text/plain", + "etag", + view->etag, filename ? "Content-Disposition" : NULL, filename ? content_disposition : NULL, };