From 0973765919408450c5187183718e1d295a1b9dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 22 Sep 2022 17:52:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=98=B2=E7=9B=97=E9=93=BE?= =?UTF-8?q?=E6=8B=A6=E6=88=AA=E6=97=B6=E9=BB=98=E8=AE=A4=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E6=96=87=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_error.go | 16 +++++++++++++--- internal/nodes/http_request_limit.go | 4 ++-- internal/nodes/http_request_referers.go | 6 +++--- internal/nodes/http_request_waf.go | 4 ++-- 4 files changed, 20 insertions(+), 10 deletions(-) diff --git a/internal/nodes/http_request_error.go b/internal/nodes/http_request_error.go index 847460b..d32cec2 100644 --- a/internal/nodes/http_request_error.go +++ b/internal/nodes/http_request_error.go @@ -25,10 +25,10 @@ const httpStatusPageTemplate = ` ` func (this *HTTPRequest) write404() { - this.writeCode(http.StatusNotFound) + this.writeCode(http.StatusNotFound, "", "") } -func (this *HTTPRequest) writeCode(statusCode int) { +func (this *HTTPRequest) writeCode(statusCode int, enMessage string, zhMessage string) { if this.doPage(statusCode) { return } @@ -42,7 +42,17 @@ func (this *HTTPRequest) writeCode(statusCode int) { case "requestId": return this.requestId case "message": - return "" // 空 + var acceptLanguages = this.RawReq.Header.Get("Accept-Language") + if len(acceptLanguages) > 0 { + var index = strings.Index(acceptLanguages, ",") + if index > 0 { + var firstLanguage = acceptLanguages[:index] + if firstLanguage == "zh-CN" { + return zhMessage + } + } + } + return enMessage } return "${" + varName + "}" }) diff --git a/internal/nodes/http_request_limit.go b/internal/nodes/http_request_limit.go index a4776ed..a6e50e4 100644 --- a/internal/nodes/http_request_limit.go +++ b/internal/nodes/http_request_limit.go @@ -18,7 +18,7 @@ func (this *HTTPRequest) doRequestLimit() (shouldStop bool) { // TODO 处理分片提交的内容 if this.web.RequestLimit.MaxBodyBytes() > 0 && this.RawReq.ContentLength > this.web.RequestLimit.MaxBodyBytes() { - this.writeCode(http.StatusRequestEntityTooLarge) + this.writeCode(http.StatusRequestEntityTooLarge, "", "") return true } @@ -29,7 +29,7 @@ func (this *HTTPRequest) doRequestLimit() (shouldStop bool) { clientConn, ok := requestConn.(ClientConnInterface) if ok && !clientConn.IsBound() { if !clientConn.Bind(this.ReqServer.Id, this.requestRemoteAddr(true), this.web.RequestLimit.MaxConns, this.web.RequestLimit.MaxConnsPerIP) { - this.writeCode(http.StatusTooManyRequests) + this.writeCode(http.StatusTooManyRequests, "", "") this.Close() return true } diff --git a/internal/nodes/http_request_referers.go b/internal/nodes/http_request_referers.go index 143312e..7225877 100644 --- a/internal/nodes/http_request_referers.go +++ b/internal/nodes/http_request_referers.go @@ -19,7 +19,7 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) { } this.tags = append(this.tags, "refererCheck") - this.writer.WriteHeader(http.StatusForbidden) + this.writeCode(http.StatusForbidden, "The referer has been blocked.", "当前访问已被防盗链系统拦截。") return true } @@ -31,14 +31,14 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) { } this.tags = append(this.tags, "refererCheck") - this.writer.WriteHeader(http.StatusForbidden) + this.writeCode(http.StatusForbidden, "The referer has been blocked.", "当前访问已被防盗链系统拦截。") return true } if !this.web.Referers.MatchDomain(this.ReqHost, u.Host) { this.tags = append(this.tags, "refererCheck") - this.writer.WriteHeader(http.StatusForbidden) + this.writeCode(http.StatusForbidden, "The referer has been blocked.", "当前访问已被防盗链系统拦截。") return true } return diff --git a/internal/nodes/http_request_waf.go b/internal/nodes/http_request_waf.go index a4d2aae..d981ba3 100644 --- a/internal/nodes/http_request_waf.go +++ b/internal/nodes/http_request_waf.go @@ -173,7 +173,7 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir if countryId > 0 && lists.ContainsInt64(regionConfig.DenyCountryIds, countryId) { this.firewallPolicyId = firewallPolicy.Id - this.writeCode(http.StatusForbidden) + this.writeCode(http.StatusForbidden, "", "") this.writer.Flush() this.writer.Close() @@ -192,7 +192,7 @@ func (this *HTTPRequest) checkWAFRequest(firewallPolicy *firewallconfigs.HTTPFir if provinceId > 0 && lists.ContainsInt64(regionConfig.DenyProvinceIds, provinceId) { this.firewallPolicyId = firewallPolicy.Id - this.writeCode(http.StatusForbidden) + this.writeCode(http.StatusForbidden, "", "") this.writer.Flush() this.writer.Close()