[jsonapi] Prevent browsers to cache playlist tracks

The tracks of a smart playlist might change between library rescans.
Allowing them to be cached based on the last rescan timestamp
("Last-Modified" header in the response) leads to potentially showing
incorrect track listing if a cached version is used. Thus the response
for playlist tracks should never be cached by the browser (this is
achieved with setting "Cache-Control" header to "no-store").
This commit is contained in:
chme 2020-08-29 12:40:49 +02:00
parent 39b14ff8d4
commit dd811e6c70
3 changed files with 21 additions and 2 deletions

View File

@ -344,6 +344,22 @@ httpd_request_not_modified_since(struct evhttp_request *req, time_t mtime)
return false;
}
void
httpd_response_not_cachable(struct evhttp_request *req)
{
struct evkeyvalq *output_headers;
output_headers = evhttp_request_get_output_headers(req);
// Remove potentially set cache control headers
evhttp_remove_header(output_headers, "Cache-Control");
evhttp_remove_header(output_headers, "Last-Modified");
evhttp_remove_header(output_headers, "ETag");
// Tell clients that they are not allowed to cache this response
evhttp_add_header(output_headers, "Cache-Control", "no-store");
}
static void
serve_file(struct evhttp_request *req, const char *uri)
{

View File

@ -107,6 +107,9 @@ httpd_request_not_modified_since(struct evhttp_request *req, time_t mtime);
bool
httpd_request_etag_matches(struct evhttp_request *req, const char *etag);
void
httpd_response_not_cachable(struct evhttp_request *req);
/*
* Gzips an evbuffer
*

View File

@ -3516,8 +3516,8 @@ jsonapi_reply_library_playlist_tracks(struct httpd_request *hreq)
int total;
int ret = 0;
if (!is_modified(hreq->req, DB_ADMIN_DB_MODIFIED))
return HTTP_NOTMODIFIED;
// Due to smart playlists possibly changing their tracks between rescans, disable caching in clients
httpd_response_not_cachable(hreq->req);
ret = safe_atoi32(hreq->uri_parsed->path_parts[3], &playlist_id);
if (ret < 0)