github.com/TeaOSLab/EdgeNode@v1.3.8/internal/nodes/http_request_user_agent.go (about) 1 // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn . 2 3 package nodes 4 5 import ( 6 "net/http" 7 ) 8 9 func (this *HTTPRequest) doCheckUserAgent() (shouldStop bool) { 10 if this.web.UserAgent == nil || !this.web.UserAgent.IsOn { 11 return 12 } 13 14 const cacheSeconds = "3600" // 时间不能过长,防止修改设置后长期无法生效 15 16 if this.web.UserAgent.MatchURL(this.URL()) && !this.web.UserAgent.AllowRequest(this.RawReq) { 17 this.tags = append(this.tags, "userAgentCheck") 18 this.writer.Header().Set("Cache-Control", "max-age="+cacheSeconds) 19 this.writeCode(http.StatusForbidden, "The User-Agent has been blocked.", "当前访问已被UA名单拦截。") 20 return true 21 } 22 23 return 24 }