简体   繁体   中英

Add Favicon to text/plain response

When a user requests my service I'd like to respond with Content-Type text/plain, but I'd also like to send the favicon with it.

Is there a way with HTTP/1.1 to send a favicon when using text/plain?

替代答案虽然Slaks是正确的,但也可以使用HTTP Link标头代替HTML <link>元素。

Link: </favicon.ico>; rel="icon"

No.

However, most browsers will try /favicon.ico if you don't have relevant tags.

you need to tell the server ( http/https ?) that respond an icon/image file when client requests /favicon.ico , since your question is broad, i am considering the case of configuring nginx , config file will be like,

server{
 server_name mydomain_name;
 location /favicon.ico {
      alias /path/to/ico/file;
 }
}

also note that as @Evert's answer it is good to return a response header from application server with response header with,

Link: </favicon.ico>; rel="icon" # header key Link is set value from application response code

If you meant case of a website/application with an HTML output on browser, most browser is compatible with <link> syntax, so between <head> add this code

<head>
<link rel="icon" href="/path/to/icon/image"/>
</head>

if you use above code in html all/first requested page, browser will set the website icon as png/jpg image from href .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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