From f005da1d5f8ad47feaa12320e031f5cbea3cab8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 2 Nov 2022 15:24:30 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E7=9B=97=E9=93=BE=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BC=93=E5=AD=98=E6=97=B6=E9=97=B4=EF=BC=8C?= =?UTF-8?q?=E4=BB=A5=E6=8F=90=E5=8D=87=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_referers.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/nodes/http_request_referers.go b/internal/nodes/http_request_referers.go index 7225877..32f13ae 100644 --- a/internal/nodes/http_request_referers.go +++ b/internal/nodes/http_request_referers.go @@ -12,6 +12,8 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) { return } + const cacheSeconds = "3600" // 时间不能过长,防止修改设置后长期无法生效 + var refererURL = this.RawReq.Header.Get("Referer") if len(refererURL) == 0 { if this.web.Referers.MatchDomain(this.ReqHost, "") { @@ -19,6 +21,7 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) { } this.tags = append(this.tags, "refererCheck") + this.writer.Header().Set("Cache-Control", "max-age="+cacheSeconds) this.writeCode(http.StatusForbidden, "The referer has been blocked.", "当前访问已被防盗链系统拦截。") return true @@ -31,6 +34,7 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) { } this.tags = append(this.tags, "refererCheck") + this.writer.Header().Set("Cache-Control", "max-age="+cacheSeconds) this.writeCode(http.StatusForbidden, "The referer has been blocked.", "当前访问已被防盗链系统拦截。") return true @@ -38,6 +42,7 @@ func (this *HTTPRequest) doCheckReferers() (shouldStop bool) { if !this.web.Referers.MatchDomain(this.ReqHost, u.Host) { this.tags = append(this.tags, "refererCheck") + this.writer.Header().Set("Cache-Control", "max-age="+cacheSeconds) this.writeCode(http.StatusForbidden, "The referer has been blocked.", "当前访问已被防盗链系统拦截。") return true }