Skip to content

Conversation

@w00000dy
Copy link
Contributor

@w00000dy w00000dy commented Jan 3, 2024

This also adds support for ETag caching for the settings pages, specifically for the following pages ETag caching is now enabled:

  • settings_wifi
  • settings_leds
  • settings_ui
  • settings_sync
  • settings_time
  • settings_sec
  • settings_dmx
  • settings_um
  • update
  • settings_2D
  • settingsCss
  • welcome
  • settings
  • liveviewws2D
  • liveview
  • settingsCss
  • favicon
  • usermod
  • index
  • pixart
  • pxmagic
  • cpal

I also fixed some issues with the previous caching not being RFC 7232 compliant.
In Section 4.1 of RFC 7232 it is defined that a 304 (Not Modified) status code indicates that a conditional GET or HEAD request has been received and would have resulted in a 200 (OK) response. This is why I added a check if the status code was 200.
Another thing that the previous implementation did not do was that the server generating a 304 response MUST generate any of the following header fields that would have been sent in a 200 (OK) response to the same request: Cache-Control, Content-Location, Date, ETag, Expires, and Vary. This is why I'm now calling the setStaticContentCacheHeaders function in the handleIfNoneMatchCacheHeader function.

To eliminate duplicate code, I created the function handleStaticContent. I added a comment that explains what this function does. Basically, now instead of having blocks like this:

server.on("/page.htm", HTTP_GET, [](AsyncWebServerRequest *request){
    if (handleFileRead(request, "/page.htm")) return;
    if (handleIfNoneMatchCacheHeader(request)) return;
    AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", PAGE_page, PAGE_page_L);
    response->addHeader(FPSTR(s_content_enc),"gzip");
    setStaticContentCacheHeaders(response);
    request->send(response);
});

We now have this:

server.on("/page.htm", HTTP_GET, [](AsyncWebServerRequest *request) {
    handleStaticContent(request, "/page.htm", 200, "text/html", PAGE_page, PAGE_page_L);
});

Which is much shorter. 😄

If you are wondering what the eTagSuffix is used for in the handleStaticContent function, it is currently not used, but I added it to have more control over caching. In the future this could be used if we want to use ETag caching for fxdata or effects.

I also fixed a small bug in cdata.js that caused favicon_length to have the wrong value.

This also adds support for ETag caching for the settings pages
Also fixed some issues with the previous caching not being RFC 7232 compliant.
Copy link
Contributor

@blazoncek blazoncek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! 👍

@blazoncek blazoncek merged commit 6ad4493 into wled:0_15 Jan 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants