Skip to content

Commit

Permalink
Merge pull request #87 from silinternational/log-bot
Browse files Browse the repository at this point in the history
log when a trusted bot is recognized
  • Loading branch information
briskt authored Dec 10, 2024
2 parents 2b87c5a + 0cdb94d commit 8d82421
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ func (p Proxy) handleRequest(w http.ResponseWriter, r *http.Request) error {
if p.isTrustedBot(r) {
upstream := p.DefaultSite
p.setVar(r, CaddyVarUpstream, upstream)
p.log.Info("trusted bot", zap.String("user-agent", r.UserAgent()), zap.String("upstream", upstream))
return nil
}

Expand Down Expand Up @@ -202,7 +203,7 @@ func (p *Proxy) isTrusted(returnTo string) bool {

func (p Proxy) setVar(r *http.Request, name, value string) {
caddyhttp.SetVar(r.Context(), name, value)
p.log.Info("setting " + name + " to " + value)
p.log.Debug("setting " + name + " to " + value)
}

func newDynamicProxy(_ httpcaddyfile.Helper) (caddyhttp.MiddlewareHandler, error) {
Expand Down Expand Up @@ -328,7 +329,7 @@ func (p Proxy) getNewToken(_ http.ResponseWriter, r *http.Request) error {
// isTrustedBot compares the user agent in the request against a list of trusted bots in the configuration and
// returns true if the user agent contains one of the configured keywords.
func (p Proxy) isTrustedBot(r *http.Request) bool {
userAgent := strings.ToLower(r.Header.Get("User-Agent"))
userAgent := strings.ToLower(r.UserAgent())
if userAgent == "" {
return false
}
Expand Down

0 comments on commit 8d82421

Please sign in to comment.