[Question] Serving GZIPped content from SPIFFS
Posted: Sun Jul 14, 2019 10:31 am
I want to serve several files from ESP32 async web server in compressed format.
For example, my 'data' folder has two files:
1. favicon.ico
2. index.html
I compress index.html to index.html.gz.
With this code, .gz archive is opening in a browser as plain text, showing a couple lines of jibberish:
With this code, as soon as I access ESP32's IP, browser tries to DL index.html.gz as an archive.
How my web server code should look like, so that the browser would upack and open .gz file as .html?
For example, my 'data' folder has two files:
1. favicon.ico
2. index.html
I compress index.html to index.html.gz.
With this code, .gz archive is opening in a browser as plain text, showing a couple lines of jibberish:
Code: Select all
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
AsyncWebServerResponse *response = request->beginResponse(200, "text/html");
response->addHeader("Content-Encoding", "gzip");
request->send(SPIFFS, "/index.html.gz", "text/html", false);
});
Code: Select all
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
AsyncWebServerResponse *response = request->beginResponse(200, "text/html");
response->addHeader("Content-Encoding", "text/html");
request->send(SPIFFS, "/index.html.gz", "text/html", false);
});