http: Fix some caching issues.

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; const char** form_data;
void* data; void* data;
size_t size; size_t size;
char etag[256];
bool not_modified; bool not_modified;
} view_t; } view_t;
@ -1245,7 +1246,7 @@ static void _httpd_endpoint_view_work(tf_ssb_t* ssb, void* user_data)
{ {
view_t* view = user_data; view_t* view = user_data;
tf_http_request_t* request = view->request; 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"); user_app_t* user_app = _parse_user_app_from_path(request->path, "/view");
if (user_app) if (user_app)
@ -1266,10 +1267,11 @@ static void _httpd_endpoint_view_work(tf_ssb_t* ssb, void* user_data)
if (*blob_id) 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"); const char* if_none_match = tf_http_request_get_header(request, "if-none-match");
char match[258]; char match[258];
snprintf(match, sizeof(match), "\"%s\"", blob_id); 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; 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", "sandbox allow-downloads allow-top-navigation-by-user-activation",
"Content-Type", "Content-Type",
view->data ? _httpd_mime_type_from_magic_bytes(view->data, view->size) : "text/plain", 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,
filename ? content_disposition : NULL, filename ? content_disposition : NULL,
}; };