aboutsummaryrefslogtreecommitdiffstats
path: root/gopherproxy.go
diff options
context:
space:
mode:
authorFeuerfuchs <git@feuerfuchs.dev>2019-06-20 15:47:04 +0200
committerFeuerfuchs <git@feuerfuchs.dev>2019-06-20 15:47:04 +0200
commitde13213492ce02464c5ecd8544ea5ae6b33fa712 (patch)
treeb227baa4ce533336fe1c8f1dbd58709d1c542714 /gopherproxy.go
parentFix for unescaped HTML (diff)
downloadgopherproxy-de13213492ce02464c5ecd8544ea5ae6b33fa712.tar.gz
gopherproxy-de13213492ce02464c5ecd8544ea5ae6b33fa712.tar.bz2
gopherproxy-de13213492ce02464c5ecd8544ea5ae6b33fa712.zip
Make output about ignored robots.txt optional
Diffstat (limited to 'gopherproxy.go')
-rw-r--r--gopherproxy.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/gopherproxy.go b/gopherproxy.go
index 74f33bb..961806a 100644
--- a/gopherproxy.go
+++ b/gopherproxy.go
@@ -87,12 +87,12 @@ func renderDirectory(w http.ResponseWriter, tpl *template.Template, styletext st
87// to the request path and renders the content using the provided template. 87// to the request path and renders the content using the provided template.
88// The optional robots parameters points to a robotstxt.RobotsData struct 88// The optional robots parameters points to a robotstxt.RobotsData struct
89// to test user agents against a configurable robotst.txt file. 89// to test user agents against a configurable robotst.txt file.
90func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, styletext string, uri string) http.HandlerFunc { 90func GopherHandler(tpl *template.Template, robotsdata *robotstxt.RobotsData, robotsdebug bool, styletext string, uri string) http.HandlerFunc {
91 return func(w http.ResponseWriter, req *http.Request) { 91 return func(w http.ResponseWriter, req *http.Request) {
92 agent := req.UserAgent() 92 agent := req.UserAgent()
93 path := strings.TrimPrefix(req.URL.Path, "/") 93 path := strings.TrimPrefix(req.URL.Path, "/")
94 94
95 if robotsdata != nil && !robotsdata.TestAgent(path, agent) { 95 if robotsdata != nil && robotsdebug && !robotsdata.TestAgent(path, agent) {
96 log.Printf("UserAgent %s ignored robots.txt", agent) 96 log.Printf("UserAgent %s ignored robots.txt", agent)
97 } 97 }
98 98
@@ -203,7 +203,7 @@ func FontHandler(woff2 bool, fontdata []byte) http.HandlerFunc {
203// specified by the request. The robots argument is a pointer to 203// specified by the request. The robots argument is a pointer to
204// a robotstxt.RobotsData struct for testing user agents against 204// a robotstxt.RobotsData struct for testing user agents against
205// a configurable robots.txt file. 205// a configurable robots.txt file.
206func ListenAndServe(bind, robotsfile, uri string) error { 206func ListenAndServe(bind, robotsfile string, robotsdebug bool, uri string) error {
207 var ( 207 var (
208 tpl *template.Template 208 tpl *template.Template
209 robotsdata *robotstxt.RobotsData 209 robotsdata *robotstxt.RobotsData
@@ -265,7 +265,7 @@ func ListenAndServe(bind, robotsfile, uri string) error {
265 log.Fatal(err) 265 log.Fatal(err)
266 } 266 }
267 267
268 http.HandleFunc("/", GopherHandler(tpl, robotsdata, styletext, uri)) 268 http.HandleFunc("/", GopherHandler(tpl, robotsdata, robotsdebug, styletext, uri))
269 http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata)) 269 http.HandleFunc("/robots.txt", RobotsTxtHandler(robotstxtdata))
270 http.HandleFunc("/favicon.ico", FaviconHandler(favicondata)) 270 http.HandleFunc("/favicon.ico", FaviconHandler(favicondata))
271 http.HandleFunc("/iosevka-term-ss03-regular.woff", FontHandler(false, fontdataw)) 271 http.HandleFunc("/iosevka-term-ss03-regular.woff", FontHandler(false, fontdataw))