http: Fix some caching issues.
All checks were successful
Build Tilde Friends / Build-All (push) Successful in 17m8s

This commit is contained in:
Cory McWilliams 2024-11-06 12:41:54 -05:00
parent 259f92c53b
commit f66cfaec12

View File

@ -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,
};