-->
Page 1 of 3

esp8266 html gzip

PostPosted: Tue May 04, 2021 5:04 pm
by GastonMelo
Hi to all,
I have an esp8266 as webserver like the example WiFiHTTPServer. I'm sending the html page like this:
Code: Select all  client.print(header);
  client.println(html_1);
  client.print(html_2);
   client.print(html_3);
  client.println(html_4);


I want to know if is possible to send the html page encoded in gzip in the form:
Code: Select allindex_html_gz[]={0x10.........0x20}


I already coded the html page using cyberchef.
Regards
Gastón

Re: esp8266 html gzip

PostPosted: Wed May 05, 2021 7:01 am
by btidey
Yes.

If you return with header attribute “Content-encoding: gzip” then the browser will unpack the contents correctly.

I do this all the time with gzip files stored in filing system in the ESP8266. It is not just html that can be handled like this but css javascript etc.

Re: esp8266 html gzip

PostPosted: Wed May 05, 2021 8:59 am
by GastonMelo
thanks for the quick reply,
i send this:
Code: Select all  client.println("HTTP/1.1 200 OK");
  client.println("Content-Encoding: gzip");
  client.println("Content-Type: text/html");
  client.println(index_html_gz[322]);

where index_html_gz is the html gziped. They did receive the gzip html but only display a white windows.
Gastón

Re: esp8266 html gzip

PostPosted: Wed May 05, 2021 4:15 pm
by btidey
That method doesn't set the http header attributes.

You can put this inside meta tags see https://www.w3schools.com/tags/att_meta_http_equiv.asp

Depending on which webserver you are using you may also be able to set the http header attributes directly. This is a cleaner way of doing it.