Skip to content

Commit

Permalink
Extend bot flag to CGI mode
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelreyna committed Aug 20, 2020
1 parent 767581d commit db2aba8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/conf/cgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (c *Conf) setupCGIRoute(args []string, srvr *server.Server) (*server.Route,
} else {
route.MaxOK = 1
}
route.HandlerFunc = handlers.HandleCGI(handler, fn, c.FileMime, srvr.InfoLog)
route.HandlerFunc = handlers.HandleCGI(handler, fn, c.FileMime, !c.AllowBots, srvr.InfoLog)

return route, nil
}
4 changes: 2 additions & 2 deletions internal/handlers/cgi.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"
)

func HandleCGI(handler *ezcgi.Handler, name, mime string, infoLog *log.Logger) func(w http.ResponseWriter, r *http.Request) error {
func HandleCGI(handler *ezcgi.Handler, name, mime string, noBots bool, infoLog *log.Logger) func(w http.ResponseWriter, r *http.Request) error {
msg := "transfer complete:\n"
msg += "\tname: %s\n"
if mime != "" {
Expand Down Expand Up @@ -39,7 +39,7 @@ func HandleCGI(handler *ezcgi.Handler, name, mime string, infoLog *log.Logger) f
}
return func(w http.ResponseWriter, r *http.Request) error {
// Filter out requests from bots, iMessage, etc.
if headers, exists := r.Header["User-Agent"]; exists {
if headers, exists := r.Header["User-Agent"]; exists && noBots {
for _, header := range headers {
isBot := strings.Contains(header, "bot")
if !isBot {
Expand Down

0 comments on commit db2aba8

Please sign in to comment.