diff --git a/internal/server/favicon.go b/internal/server/favicon.go new file mode 100644 index 0000000..bdb4872 --- /dev/null +++ b/internal/server/favicon.go @@ -0,0 +1,23 @@ +package server + +import "net/http" + +const faviconSVG = `` + +func (s *Server) serveFavicon(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet && r.Method != http.MethodHead { + w.Header().Set("Allow", "GET, HEAD") + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + w.Header().Set("Content-Type", "image/svg+xml; charset=utf-8") + w.Header().Set("Cache-Control", "public, max-age=86400") + if r.Method == http.MethodHead { + return + } + _, _ = w.Write([]byte(faviconSVG)) +} diff --git a/internal/server/server.go b/internal/server/server.go index 744e9da..1eff852 100644 --- a/internal/server/server.go +++ b/internal/server/server.go @@ -45,6 +45,10 @@ func (s *Server) SetStats(q StatsQuerier) { // ServeHTTP handles incoming HTTP requests strictly on the configured single endpoint. func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { + if r.URL.Path == "/favicon.svg" { + s.serveFavicon(w, r) + return + } if r.URL.Path == "/monitor" || strings.HasPrefix(r.URL.Path, "/monitor/") { s.serveMonitor(w, r) return @@ -620,6 +624,7 @@ a:hover { color: var(--accent); }
+