From 1015221e90c63a544567e5e33d1e21dca2a9ec36 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Thu, 21 Oct 2021 17:09:51 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8D=95=E4=B8=AA=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=E7=9A=84=E5=B8=A6=E5=AE=BD=E9=99=90=E5=88=B6=EF=BC=88?= =?UTF-8?q?=E5=95=86=E4=B8=9A=E7=89=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request.go | 7 ++++++ .../nodes/http_request_bandwidth_limit.go | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 internal/nodes/http_request_bandwidth_limit.go diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index 29ed6c3..a778370 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -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() { diff --git a/internal/nodes/http_request_bandwidth_limit.go b/internal/nodes/http_request_bandwidth_limit.go new file mode 100644 index 0000000..979bf8c --- /dev/null +++ b/internal/nodes/http_request_bandwidth_limit.go @@ -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) + } +}