Home > Net >  It is possible to return a GET /favicon.ico request with a string ecoded image?
It is possible to return a GET /favicon.ico request with a string ecoded image?

Time:12-12

I have a webserver setup on my iot device. The device is not really powerful and does not have a file system to store images from.

Nonetheless i would still want to have a favicon given to the browsers that request it. Since I do not have a File System I was planning of saving the image directly into the source code of the device. I have read in this thread that you can convert an image into an encoded string so i can then save the encoded string into a variable somethingg like

String imageString = "Encoded String Here";

So here is google chrome favicon http request looks like

20:46:21.767 -> GET /favicon.ico HTTP/1.1
20:46:21.767 -> Host: 192.168.1.8
20:46:21.767 -> Connection: keep-alive
20:46:21.767 -> User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.93 Safari/537.36
20:46:21.814 -> Accept: image/avif,image/webp,image/apng,image/svg xml,image/*,*/*;q=0.8
20:46:21.814 -> Referer: http://192.168.1.8/
20:46:21.814 -> Accept-Encoding: gzip, deflate
20:46:21.814 -> Accept-Language: en-US,en;q=0.9,fil;q=0.8

My webserver can only respond to request in pure text. So how would my response look like that the image is now in text format??

HTTP/1.1 200 OK
Connection: close
Content-Type: text/html

//Do i place the encoded string here?? will the browser understand that?

CodePudding user response:

You can generate a base64 string of your favicon and then insert it into the head of the html document like this:

<link href="data:image/x-icon;base64,<your_base64_here>" rel="icon" type="image/x-icon" />
  • Related