add gzip support

This commit is contained in:
cjkas 2026-03-12 13:59:17 +01:00
parent a64b648f7a
commit 96d66c1b45
3 changed files with 13 additions and 7 deletions

1
.gitignore vendored
View file

@ -9,3 +9,4 @@ SomfyController.ino.esp32c3.bin
SomfyController.ino.esp32s2.bin SomfyController.ino.esp32s2.bin
.vscode/settings.json .vscode/settings.json
.pio .pio
data

View file

@ -22,6 +22,7 @@ lib_deps =
knolleary/PubSubClient@^2.8 knolleary/PubSubClient@^2.8
extra_scripts = pre:minify.py extra_scripts = pre:minify.py
board_build.partitions = min_spiffs.csv board_build.partitions = min_spiffs.csv
board_build.filesystem = littlefs
[env:esp32devdbg] [env:esp32devdbg]
build_type = debug build_type = debug
@ -35,3 +36,4 @@ lib_deps =
knolleary/PubSubClient@^2.8 knolleary/PubSubClient@^2.8
extra_scripts = pre:minify.py extra_scripts = pre:minify.py
board_build.partitions = min_spiffs.csv board_build.partitions = min_spiffs.csv
board_build.filesystem = littlefs

View file

@ -216,14 +216,17 @@ void Web::handleStreamFile(WebServer &server, const char *filename, const char *
webServer.sendCORSHeaders(server); webServer.sendCORSHeaders(server);
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; } if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
esp_task_wdt_reset(); esp_task_wdt_reset();
// Load the index html page from the data directory. // Try gzip variant first; streamFile() auto-adds Content-Encoding: gzip for .gz files
Serial.print("Loading file "); String gzFilename = String(filename) + ".gz";
Serial.println(filename); File file = LittleFS.open(gzFilename.c_str(), "r");
File file = LittleFS.open(filename, "r"); if (!file) {
file = LittleFS.open(filename, "r");
}
if (!file) { if (!file) {
Serial.print("Error opening "); Serial.print("Error opening ");
Serial.println(filename); Serial.println(filename);
server.send(500, _encoding_text, "Error opening file"); server.send(500, _encoding_text, "Error opening file");
return;
} }
esp_task_wdt_delete(NULL); esp_task_wdt_delete(NULL);
server.streamFile(file, encoding); server.streamFile(file, encoding);