cpp-httplib icon indicating copy to clipboard operation
cpp-httplib copied to clipboard

Use cache validation in serving of files

Open Spixmaster opened this issue 5 months ago • 0 comments

I have an HTTP server which among other things serves static files via server->set_mount_point(constant::endpoint::mount_point, constant::directory::shared());.

If I understand correctly, Server::handle_file_request() is responsible for serving files from the mount point. I do not see validation mechanisms like Last-Modified or ETag which would save bandwidth with the only little downside of calculating an identifier like a hash.

There is a tendency that ETag is preferred over Last-Modified.

Good resources:

  • https://http.dev/caching
  • https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag
  • https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/If-None-Match
  • https://www.rfc-editor.org/rfc/rfc9110.html#name-304-not-modified

Spixmaster avatar Sep 22 '25 12:09 Spixmaster