Files
EdgeNode/internal/nodes/http_request_user_agent.go
GoEdgeLab c19be78e0d v1.4.1
2024-07-27 15:42:50 +08:00

25 lines
733 B
Go

// Copyright 2022 GoEdge goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cloud .
package nodes
import (
"net/http"
)
func (this *HTTPRequest) doCheckUserAgent() (shouldStop bool) {
if this.web.UserAgent == nil || !this.web.UserAgent.IsOn {
return
}
const cacheSeconds = "3600" // 时间不能过长,防止修改设置后长期无法生效
if this.web.UserAgent.MatchURL(this.URL()) && !this.web.UserAgent.AllowRequest(this.RawReq) {
this.tags = append(this.tags, "userAgentCheck")
this.writer.Header().Set("Cache-Control", "max-age="+cacheSeconds)
this.writeCode(http.StatusForbidden, "The User-Agent has been blocked.", "当前访问已被UA名单拦截。")
return true
}
return
}