diff options
Diffstat (limited to 'internal/web/handlers_media.go')
| -rw-r--r-- | internal/web/handlers_media.go | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/internal/web/handlers_media.go b/internal/web/handlers_media.go index e651135..9d5a515 100644 --- a/internal/web/handlers_media.go +++ b/internal/web/handlers_media.go @@ -3,6 +3,7 @@ package web import ( "bytes" "errors" + "io/fs" "net/http" "github.com/google/uuid" @@ -36,3 +37,23 @@ func (s *Server) handleMedia(w http.ResponseWriter, r *http.Request) { w.Header().Set("X-Content-Type-Options", "nosniff") http.ServeContent(w, r, img.Filename, img.CreatedAt, bytes.NewReader(img.Data)) } + +// handleFavicon answers the browsers that ask for /favicon.ico regardless of +// the <link rel="icon"> tags: the blog's own icon if it set one, else the +// Blogspace default. Without this the request would render the 404 page. +func (s *Server) handleFavicon(w http.ResponseWriter, r *http.Request) { + if icon := ParseTheme(currentBlog(r).ThemeJSON).Favicon; icon != "" { + http.Redirect(w, r, "/media/"+icon, http.StatusFound) + return + } + data, err := fs.ReadFile(s.tpl.AssetsFS(), "favicon.png") + if err != nil { + s.serverError(w, err) + return + } + w.Header().Set("Content-Type", "image/png") + if !s.cfg.Dev { + w.Header().Set("Cache-Control", "public, max-age=3600") + } + w.Write(data) +} |
