From adf557bde474b203a322d2ce692bd5552c8fefd4 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Wed, 30 Oct 2019 17:19:05 +1100 Subject: [PATCH] Set cache-control max-age: 0 for when downloading skins in the web client. This way we'll still get 304 responses for 99% of skin fetches. Still not as ideal as the old method where they would be retrieved from the browser cache instead, but this way means skins changes show up instantly instead of after 1-3 hours. (this has been grumbled about quite a bit) --- src/Http.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/Http.c b/src/Http.c index f16dfd48f..950a9ccd5 100644 --- a/src/Http.c +++ b/src/Http.c @@ -382,9 +382,20 @@ static void Http_DownloadAsync(struct HttpRequest* req) { attr.requestDataSize = req->Size; } - /* TODO: Why does this break */ - /*static const char* headers[3] = { "cache-control", "max-age=0", NULL }; */ - /*attr.requestHeaders = headers; */ + /* Can't use this for all URLs, because cache-control isn't in allowed CORS headers */ + /* For example, if you try this with dropbox, you'll get a '404' with + /* Access to XMLHttpRequest at 'https://dl.dropbox.com/s/a/a.zip' from + /* origin 'http://www.classicube.net' has been blocked by CORS policy: + /* Response to preflight request doesn't pass access control check: + /* Redirect is not allowed for a preflight request. */ + /* printed to console. But this is still used for skins, that way when users change */ + /* their skins, the change shows up instantly. But 99% of the time we'll get a 304 */ + /* response and can avoid downloading the whole skin over and over. */ + if (urlStr[0] == '/') { + static const char* const headers[3] = { "cache-control", "max-age=0", NULL }; + attr.requestHeaders = headers; + } + attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY; attr.onsuccess = Http_FinishedAsync; attr.onerror = Http_FinishedAsync;