diff options
author | Antoni Sawicki <tenox@google.com> | 2022-06-21 03:21:11 -0700 |
---|---|---|
committer | Antoni Sawicki <tenox@google.com> | 2022-06-21 03:21:11 -0700 |
commit | 1f6cd26f68602e2832df9316f86e92800317e8e8 (patch) | |
tree | 43f45a5d46d3743bd0776bc1bb8671bd834c6db7 | |
parent | 20a3c6aed38f4980abbc25794a1e7d9214b937f9 (diff) | |
download | wfm-1f6cd26f68602e2832df9316f86e92800317e8e8.tar.gz |
add robots.txt support
-rw-r--r-- | formats.go | 6 | ||||
-rw-r--r-- | handlers.go | 18 | ||||
-rw-r--r-- | wfm.go | 4 |
3 files changed, 19 insertions, 9 deletions
@@ -13,7 +13,6 @@ import ( "strings" "syscall" - ico "github.com/biessek/golang-ico" "github.com/bodgit/sevenzip" "github.com/dustin/go-humanize" "github.com/kdomanski/iso9660" @@ -29,11 +28,6 @@ var ( favIcn = genFavIcon() ) -func dispFavIcon(w http.ResponseWriter) { - w.Header().Set("Content-Type", "image/x-icon") - ico.Encode(w, favIcn) -} - func genFavIcon() *image.NRGBA { i := image.NewNRGBA(image.Rect(0, 0, 16, 16)) d := &font.Drawer{ diff --git a/handlers.go b/handlers.go index 47e5486..f2b1021 100644 --- a/handlers.go +++ b/handlers.go @@ -1,11 +1,14 @@ package main import ( + "fmt" "log" "net/http" "net/url" "path/filepath" "strings" + + ico "github.com/biessek/golang-ico" ) type wfmRequest struct { @@ -120,8 +123,19 @@ func wfmMain(w http.ResponseWriter, r *http.Request) { } } -func favicon(w http.ResponseWriter, r *http.Request) { - dispFavIcon(w) +func dispFavIcon(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "image/x-icon") + ico.Encode(w, favIcn) +} + +func dispRobots(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/plain") + fmt.Fprintln(w, "User-agent: *") + if *robots { + fmt.Fprintln(w, "Allow: /") + return + } + fmt.Fprintln(w, "Disallow: /") } func noText(m map[string][]string) map[string][]string { @@ -38,6 +38,7 @@ var ( wfmPfx = flag.String("prefix", "/", "Default url prefix for WFM access") docSrv = flag.String("doc_srv", "", "Serve regular http files, fsdir:prefix, eg /var/www/:/home/") cacheCtl = flag.String("cache_ctl", "no-cache", "HTTP Header Cache Control") + robots = flag.Bool("robots", false, "allow robots") acmDir = flag.String("acm_dir", "", "autocert cache, eg: /var/cache (inside chroot)") acmBind = flag.String("acm_addr", "", "autocert manager listen address, eg: :80") acmWhlist multiString // this flag set in main @@ -159,7 +160,8 @@ func main() { // http stuff mux := http.NewServeMux() mux.HandleFunc(*wfmPfx, wfmMain) - mux.HandleFunc("/favicon.ico", favicon) + mux.HandleFunc("/favicon.ico", dispFavIcon) + mux.HandleFunc("/robots.txt", dispRobots) if *f2bDump != "" { mux.HandleFunc(*f2bDump, dumpf2b) } |