[Question] Serving GZIPped content from SPIFFS

Nogla1
Posts: 3
Joined: Sun Jul 14, 2019 10:19 am

[Question] Serving GZIPped content from SPIFFS

Postby Nogla1 » 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:

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?

dimecho
Posts: 1
Joined: Wed Mar 04, 2020 9:08 pm

Re: [Question] Serving GZIPped content from SPIFFS

Postby dimecho » Wed Mar 04, 2020 9:12 pm

Code: Select all

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

Who is online

Users browsing this forum: Bing [Bot] and 108 guests