简体   繁体   English

可以返回带有字符串编码图像的 GET /favicon.ico 请求吗?

[英]It is possible to return a GET /favicon.ico request with a string ecoded image?

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所以这里是 google chrome favicon http 请求看起来像

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?

You can generate a base64 string of your favicon and then insert it into the head of the html document like this:您可以生成您的 favicon 的 base64 字符串,然后将其插入 html 文档的头部,如下所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM