1

I am trying to make an arduino webserver, and this part is done. Now I need to use some compression.

Here is my simple.htm webpage I want to serve

<!DOCTYPE html>
<html>
<body>
<h1>My First Heading</h1>
<p>My first paragraph.</p>
</body>
</html>

I tried to gzip this ( tried different tools, commandline gzip, keka, both slightly different), and got the simple.htm.gz. I opened it in a text editor and it looked like this

ã˝…Vsimple.htm-å;Ä D{OÅêÿoh¸ƒ∆hacπ?§·ˆ.ƒÍeÊe vjñuÓÑ
ש
¯±=:™Çc≠∆(zÁfl ܵª
H.YQ2G6ÑçG≤HJNÊ=3fl}?ı=me

In the server, I did this

char *htmlContent="ã˝…Vsimple.htm-å;Ä D{OÅêÿoh¸ƒ∆hacπ?§·ˆ.ƒÍeÊe vjñuÓÑ◊©¯±=:™Çc≠∆(zÁfl ܵªH.YQ2G6ÑçG≤HJNÊ=3fl}?ı=me"

I served header and content, including "Content-Encoding: gzip"; But chrome says

This webpage is not available

ERR_CONTENT_DECODING_FAILED

I know my webserver works without gzip and I have tested it and I can see it on the browser. What am I doing wrong here with gzip?

Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
aVC
  • 2,254
  • 2
  • 24
  • 46

1 Answers1

1

Your copy and paste from the textfile probably removed some non-printable charactes. At any rate, it removed any newline characters, as you can clearly see.

Now, gzip'ed files aren't ASCII and you really shouldn't be treating them like string literals in C. At the very least, you will have to replace all non-ASCII characters by their escaped representation.

Generally, the right way to go about this is probably add the compressed file to the data or text section of your binary, and use its address where you need it.

Here's an answer that explains how to add a binary blob to your object file and how to access it from your C code.

Community
  • 1
  • 1
Marcus Müller
  • 34,677
  • 4
  • 53
  • 94
  • Muller thanks, I was suspecting that. So, is there any way to include a gzipped content as a string inside a c program? – aVC Feb 21 '16 at 21:55
  • as a *string* in the narrow sense, no. It's not a string, as it might as well contain 0-bytes in the middle. But as a char array: sure. – Marcus Müller Feb 21 '16 at 21:56
  • Muller Thanks very much, really appreciate it. I think I can make use of that link you included. – aVC Feb 21 '16 at 21:59