MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / doCheckUserAgent

Method doCheckUserAgent

internal/nodes/http_request_user_agent.go:9–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7)
8
9func (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}

Callers 1

DoMethod · 0.95

Calls 4

URLMethod · 0.95
writeCodeMethod · 0.95
SetMethod · 0.45
HeaderMethod · 0.45

Tested by

no test coverage detected