From 0337f3c56cd075e4f522b58f5dd7880d78938f12 Mon Sep 17 00:00:00 2001 From: Feuerfuchs Date: Mon, 17 Jun 2019 12:28:31 +0200 Subject: Add Favicon --- assets/favicon.ico | Bin 0 -> 5430 bytes gopherproxy.go | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 assets/favicon.ico diff --git a/assets/favicon.ico b/assets/favicon.ico new file mode 100644 index 0000000..b6d0998 Binary files /dev/null and b/assets/favicon.ico differ diff --git a/gopherproxy.go b/gopherproxy.go index b65418d..f034cb9 100644 --- a/gopherproxy.go +++ b/gopherproxy.go @@ -166,6 +166,18 @@ func RobotsTxtHandler(robotstxtdata []byte) http.HandlerFunc { } } +func FaviconHandler(favicondata []byte) http.HandlerFunc { + return func(w http.ResponseWriter, req *http.Request) { + if favicondata == nil { + http.Error(w, "Not Found", http.StatusNotFound) + return + } + + w.Header().Set("Content-Type", "image/vnd.microsoft.icon") + w.Write(favicondata) + } +} + func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc { return func(w http.ResponseWriter, req *http.Request) { if fontdata == nil { @@ -225,6 +237,11 @@ func ListenAndServe(bind, robotsfile, uri string) error { styletext = "" } + favicondata, err := box.Find("favicon.ico") + if err != nil { + favicondata = []byte{} + } + tpldata, err := ioutil.ReadFile(".template") if err == nil { tpltext = string(tpldata) @@ -246,6 +263,7 @@ func ListenAndServe(bind, robotsfile, uri string) error { http.HandleFunc("/", GopherHandler(tpl, robotsdata, styletext, uri)) http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata)) + http.HandleFunc("/favicon.ico", FaviconHandler(favicondata)) http.HandleFunc("/iosevka-term-ss03-regular.woff", FontHandler(false, fontdataw)) http.HandleFunc("/iosevka-term-ss03-regular.woff2", FontHandler(true, fontdataw2)) //http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets/")))) -- cgit v1.2.3-70-g09d2