| 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 | } |