Skip to content

setTemplateProcessor() causes incorrect ETag and Last-Modified headers to be returned for static files #237

@m-z-b

Description

@m-z-b

Platform

ESP32

IDE / Tooling

PlatformIO

What happened?

When using ASyncWebServer::serveStatic() with SetTemplateProcessor ETag and Last-Modified headers are returned based on the file system date.

This is incorrect if the template processor produces any dynamic content (e.g. the current time).

The browser will receives 304 Not Modified response on subsequent requests. In addition, if the Last-Modified header is suppressed, most browsers will not re-render the page if the ETag is unchanged.

The suggested resolution is that ASyncStaticWebHandler::handleRequest assumes not_modified is false if a _callback exists, and does not include ETag or Last-Modified headers in the response.

Stack Trace

No stack trace

Minimal Reproductible Example (MRE)

Snippets - assume that LittleFS contains a /status/index.html file with a date from 2024.

AsyncWebServer webServer(80);
...
  webServer.serveStatic("/", LittleFS, "/status/", "no-cache")
    .setDefaultFile("index.html")
    .setTemplateProcessor(StatusProcessor)
      ;
$ curl -i http://esp32-hrv.arl/
HTTP/1.1 200 OK
content-disposition: inline
etag: 1734923401
last-modified: Mon, 23 Dec 2024 02:52:34 GMT
cache-control: no-cache
connection: close
accept-ranges: none
transfer-encoding: chunked
content-type: text/html

...

I confirm that:

  • I have read the documentation.
  • I have searched for similar discussions.
  • I have searched for similar issues.
  • I have looked at the examples.
  • I have upgraded to the lasted version of ESPAsyncWebServer (and AsyncTCP for ESP32).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: BugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions