mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
实现单个服务的带宽限制(商业版)
This commit is contained in:
@@ -137,6 +137,13 @@ func (this *HTTPRequest) Do() {
|
||||
}
|
||||
}
|
||||
|
||||
// 带宽限制
|
||||
if this.Server.BandwidthLimit != nil && this.Server.BandwidthLimit.IsOn && !this.Server.BandwidthLimit.IsEmpty() && this.Server.BandwidthLimitStatus != nil && this.Server.BandwidthLimitStatus.IsValid() {
|
||||
this.doBandwidthLimit()
|
||||
this.doEnd()
|
||||
return
|
||||
}
|
||||
|
||||
// WAF
|
||||
if this.web.FirewallRef != nil && this.web.FirewallRef.IsOn {
|
||||
if this.doWAFRequest() {
|
||||
|
||||
24
internal/nodes/http_request_bandwidth_limit.go
Normal file
24
internal/nodes/http_request_bandwidth_limit.go
Normal file
@@ -0,0 +1,24 @@
|
||||
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
||||
|
||||
package nodes
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
// 带宽限制
|
||||
func (this *HTTPRequest) doBandwidthLimit() {
|
||||
var config = this.Server.BandwidthLimit
|
||||
|
||||
this.tags = append(this.tags, "bandwidth")
|
||||
|
||||
var statusCode = 509
|
||||
this.processResponseHeaders(statusCode)
|
||||
|
||||
this.writer.WriteHeader(statusCode)
|
||||
if len(config.NoticePageBody) != 0 {
|
||||
_, _ = this.writer.WriteString(config.NoticePageBody)
|
||||
} else {
|
||||
_, _ = this.writer.WriteString(serverconfigs.DefaultBandwidthLimitNoticePageBody)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user