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

3
.gitignore vendored
View file

@ -8,4 +8,5 @@ SomfyController.ino.XIAO_ESP32S3.bin
SomfyController.ino.esp32c3.bin
SomfyController.ino.esp32s2.bin
.vscode/settings.json
.pio
.pio
data

View file

@ -22,6 +22,7 @@ lib_deps =
knolleary/PubSubClient@^2.8
extra_scripts = pre:minify.py
board_build.partitions = min_spiffs.csv
board_build.filesystem = littlefs
[env:esp32devdbg]
build_type = debug
@ -34,4 +35,5 @@ lib_deps =
lsatan/SmartRC-CC1101-Driver-Lib@^2.5.7
knolleary/PubSubClient@^2.8
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);
if(server.method() == HTTP_OPTIONS) { server.send(200, "OK"); return; }
esp_task_wdt_reset();
// Load the index html page from the data directory.
Serial.print("Loading file ");
Serial.println(filename);
File file = LittleFS.open(filename, "r");
// Try gzip variant first; streamFile() auto-adds Content-Encoding: gzip for .gz files
String gzFilename = String(filename) + ".gz";
File file = LittleFS.open(gzFilename.c_str(), "r");
if (!file) {
Serial.print("Error opening");
file = LittleFS.open(filename, "r");
}
if (!file) {
Serial.print("Error opening ");
Serial.println(filename);
server.send(500, _encoding_text, "Error opening file");
return;
}
esp_task_wdt_delete(NULL);
server.streamFile(file, encoding);