mathieucarbou / ESPAsyncWebServer

Asynchronous HTTP and WebSocket Server Library for ESP32, ESP8266 and RP2040
https://mathieu.carbou.me/ESPAsyncWebServer/
GNU Lesser General Public License v3.0
87 stars 17 forks source link

When using TemplateProcessor for serveStatic pages do not respond "304 Not Modified" #146

Closed mawi42 closed 1 month ago

mawi42 commented 1 month ago

When template processor is used do not return "not modifed 304" but refresh the webpage. Template processors might be used for non static pages since some variables which will be replaced might change.

Proposed workaround instead of introducing new method serveDynamic, use info if templat processor is set (_callback).

Webhandlers.cpp line 218:

if (!_callback && _last_modified.length() && _last_modified == request->header(T_IMS)) {
      request->_tempFile.close();
      request->send(304); // Not modified
    } else if(!_callback && _cache_control.length() && request->hasHeader(T_INM) && request->header(T_INM).equals(etag)) {
mathieucarbou commented 1 month ago

Hello,

Your proposal cannot be implemented like you suggest, otherwise this is a behaviour change for any person who are using the callback mechanism and still have content that can be cached.

Could you please elaborate a big more on your use can with a code sample instead of suggesting a fix which breaks existing behaviour ?

AsyncStaticWebHandler is a subclass specifically designed to serve static content that can be cached.

If this is not what you want, then, don't use it...

Thanks :-)