Support HEAD requests and improve ETag caching for static files #2198
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements comprehensive HTTP caching improvements for static files in OpenDTU-OnBattery, addressing browser caching issues introduced in #1898.
Key Changes
1. Enhanced Cache-Control Headers
Cache-Control: public, must-revalidate
(forced revalidation on every request)Cache-Control: public, max-age=2678400
(31-day caching as requested)2. HEAD Request Support
All static file routes now support HEAD requests alongside GET requests:
/
and/index.html
(gzipped HTML)/favicon.ico
and/favicon.png
(icons)/zones.json
(gzipped JSON)/site.webmanifest
(JSON)/js/app.js
(gzipped JavaScript with bundled CSS)HEAD requests return proper headers including
Content-Length
but no response body, following HTTP specification.3. Robust ETag Comparison
The ETag validation logic has been significantly improved to handle browser inconsistencies:
4. HTTP_HEAD Compatibility
Added fallback definition for older ESPAsyncWebServer versions:
Benefits
Testing
The implementation can be tested using curl commands as described in the original issue:
Expected behavior:
Fixes #2003.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.registry.nm1.platformio.org
/usr/bin/python3 /home/REDACTED/.local/bin/pio run --environment generic_esp32s3_usb --target compiledb
(dns block)/usr/bin/python3 /home/REDACTED/.local/bin/pio run --environment generic_esp32s3_usb --verbose
(dns block)api.registry.platformio.org
/usr/bin/python3 /home/REDACTED/.local/bin/pio run --environment generic_esp32s3_usb --target compiledb
(dns block)/usr/bin/python3 /home/REDACTED/.local/bin/pio run --environment generic_esp32s3_usb --verbose
(dns block)collector.platformio.org
/usr/bin/python3 /home/REDACTED/.local/bin/pio run --environment generic_esp32s3_usb --target compiledb
(dns block)/usr/bin/python3 /home/REDACTED/.local/bin/pio run --environment generic_esp32s3_usb --verbose
(dns block)If you need me to access, download, or install something from one of these locations, you can either:
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.