Page 1 of 1

[Question] Serving GZIPped content from SPIFFS

Posted: Sun Jul 14, 2019 10:31 am
by Nogla1
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:

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);
  });
With this code, as soon as I access ESP32's IP, browser tries to DL index.html.gz as an archive.

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);
  });
How my web server code should look like, so that the browser would upack and open .gz file as .html?

Re: [Question] Serving GZIPped content from SPIFFS

Posted: Wed Mar 04, 2020 9:12 pm
by dimecho

Code: Select all

AsyncWebServerResponse *response = request->beginResponse(SPIFFS, "/index.html.gz", "text/html", false);
response->addHeader("Content-Encoding", "gzip");
request->send(response);