Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log when a trusted bot is recognized #87

Merged
merged 2 commits into from
Dec 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading