Skip to content

Support HEAD request and If-None-Match as well as ETag for Cache of Static HTML, /js/app.js.gz and css files #2003

@stefan123t

Description

@stefan123t

What happened?

Files are not cached any more since #1897 added Cache-Control: public, must-revalidate and effectively disabled the browser Cache.
The above fix was introduced in #1898

To Reproduce Bug

Use the CURL commands described in #1897 (comment) and following comments to verify using the command line.

Expected Behavior

@schlimmchen as requested I have created this issue with the following points:

  • Static files should have the Cache-Control: public, max-age=2678400 which would cache for 31 days.
  • In case of static files like /js/app.js.gz and css files we should keep precalculated md5sums of the files somewhere to make calculation less effort for the ESP32AsyncWebServer. I do not know whether you would already hash it together with the githash of the current OpenDTU-OnBattery firmware version.
  • I think about language files, as well as pin_mapping.json and config.json, which may persist an OpenDTU update and therefor we would need the md5sum of the file to calculate the md5sum combined with the githash.
  • HEAD should verify the If-None-Match request header with the ETag for the resource being requested.
  • So we will have to make some sanitation, e.g. all lowercase and remove quotes if existing.
    • Even if we send the ETag with double quotes we can't rely that every browser sends back the value in double quotes. We have seen several browsers which are NOT returning the ETag in double quotes (for example the OEM Samsung browser) which makes the server comparison more difficult.
    • Don't rely on that you will receive the HTTP Header field exactly as If-None-Match, be prepared to get it in small or capital letters also.
  • GET on static files should also verify the If-None-Match request header with the ETag for the resource.
  • In case they match the response should be HTTP/1.1 304 Not Modified
            if (server.header("If-None-Match") == eTagCode) {
                server.send(304);
                return true;
            }

Install Method

Pre-Compiled binary from GitHub releases

What git-hash/version of OpenDTU-OnBattery?

#1898

What firmware variant (PIO Environment)?

generic_esp32s3_usb

Relevant log/trace output

Anything else?

Thanks for considering this to fix this issue.
As mentioned in the other issue this was a very quick and graspable overview as it included some pictures of the communication flow.
https://werner.rothschopf.net/microcontroller/202011_arduino_webserver_caching_en.htm

Please confirm the following

  • I believe this issue is a bug that affects all users of OpenDTU-OnBattery, not something specific to my installation.
  • I have already searched for relevant existing issues and discussions before opening this report.
  • I have updated the title field above with a concise description.
  • I have double checked that my inverter does not contain a W in the model name (like HMS-xxxW) as they are not supported.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions