From b63efeffa1a545e6073e993b052e6bd9162d904a Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 19 Oct 2021 16:31:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=E6=94=AF?= =?UTF-8?q?=E6=8C=81UserAgent=E5=92=8C=E6=98=AF=E5=90=A6=E5=9F=BA=E7=A1=80?= =?UTF-8?q?=E8=AF=B7=E6=B1=82=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request.go | 8 ++++++ internal/nodes/http_request_health_check.go | 27 +++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 internal/nodes/http_request_health_check.go diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index f7dee16..03c97de 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -177,6 +177,14 @@ func (this *HTTPRequest) doBegin() { } } + // 处理健康检查 + var healthCheckKey = this.RawReq.Header.Get(serverconfigs.HealthCheckHeaderName) + if len(healthCheckKey) > 0 { + if this.doHealthCheck(healthCheckKey) { + return + } + } + // 统计 if this.web.StatRef != nil && this.web.StatRef.IsOn { this.doStat() diff --git a/internal/nodes/http_request_health_check.go b/internal/nodes/http_request_health_check.go new file mode 100644 index 0000000..47b5a6d --- /dev/null +++ b/internal/nodes/http_request_health_check.go @@ -0,0 +1,27 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. + +package nodes + +import ( + "github.com/TeaOSLab/EdgeCommon/pkg/nodeutils" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/TeaOSLab/EdgeNode/internal/remotelogs" +) + +// 健康检查 +func (this *HTTPRequest) doHealthCheck(key string) (stop bool) { + this.tags = append(this.tags, "healthCheck") + + this.RawReq.Header.Del(serverconfigs.HealthCheckHeaderName) + + data, err := nodeutils.DecryptData(sharedNodeConfig.NodeId, sharedNodeConfig.Secret, key) + if err != nil { + remotelogs.Error("HTTP_REQUEST_HEALTH_CHECK", "decode key failed: "+err.Error()) + return + } + + if data.GetBool("onlyBasicRequest") { + return true + } + return +}