MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / doTrafficLimit

Method doTrafficLimit

internal/nodes/http_request_traffic_limit.go:10–47  ·  view source on GitHub ↗

流量限制

(status *serverconfigs.TrafficLimitStatus)

Source from the content-addressed store, hash-verified

8
9// 流量限制
10func (this *HTTPRequest) doTrafficLimit(status *serverconfigs.TrafficLimitStatus) (blocked bool) {
11 if status == nil {
12 return false
13 }
14
15 // 如果是网站单独设置的流量限制,则检查是否已关闭
16 var config = this.ReqServer.TrafficLimit
17 if (config == nil || !config.IsOn) && status.PlanId == 0 {
18 return false
19 }
20
21 // 如果是套餐设置的流量限制,即使套餐变更了(变更套餐或者变更套餐的限制),仍然会提示流量超限
22
23 this.tags = append(this.tags, "trafficLimit")
24
25 var statusCode = 509
26 this.writer.statusCode = statusCode
27 this.ProcessResponseHeaders(this.writer.Header(), statusCode)
28
29 this.writer.Header().Set("Content-Type", "text/html; charset=utf-8")
30 this.writer.WriteHeader(statusCode)
31
32 // check plan traffic limit
33 if (config == nil || !config.IsOn) && this.ReqServer.PlanId() > 0 && this.nodeConfig != nil {
34 var planConfig = this.nodeConfig.FindPlan(this.ReqServer.PlanId())
35 if planConfig != nil && planConfig.TrafficLimit != nil && planConfig.TrafficLimit.IsOn {
36 config = planConfig.TrafficLimit
37 }
38 }
39
40 if config != nil && len(config.NoticePageBody) != 0 {
41 _, _ = this.writer.WriteString(this.Format(config.NoticePageBody))
42 } else {
43 _, _ = this.writer.WriteString(this.Format(serverconfigs.DefaultTrafficLimitNoticePageBody))
44 }
45
46 return true
47}

Callers 1

DoMethod · 0.95

Calls 6

FormatMethod · 0.95
WriteStringMethod · 0.80
WriteHeaderMethod · 0.65
HeaderMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected