From beb60fcacd21b5e0f994644c76079c86876ca171 Mon Sep 17 00:00:00 2001 From: mamba <371510756@qq.com> Date: Tue, 11 Mar 2025 12:54:40 +0800 Subject: [PATCH] =?UTF-8?q?bugfix=EF=BC=9A=E3=80=90frontend-gray=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E3=80=91=E9=92=88=E5=AF=B9fetch=E7=9A=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=EF=BC=8C=E5=BC=BA=E5=88=B6=E4=B8=8D=E7=BC=93=E5=AD=98?= =?UTF-8?q?=20(#1856)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/wasm-go/extensions/frontend-gray/config/config.go | 1 + plugins/wasm-go/extensions/frontend-gray/main.go | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/plugins/wasm-go/extensions/frontend-gray/config/config.go b/plugins/wasm-go/extensions/frontend-gray/config/config.go index b624efa3b..43d7225c4 100644 --- a/plugins/wasm-go/extensions/frontend-gray/config/config.go +++ b/plugins/wasm-go/extensions/frontend-gray/config/config.go @@ -13,6 +13,7 @@ const ( IsPageRequest = "is-page-request" IsNotFound = "is-not-found" EnabledGray = "enabled-gray" + SecFetchMode = "sec-fetch-mode" ) type LogInfo func(format string, args ...interface{}) diff --git a/plugins/wasm-go/extensions/frontend-gray/main.go b/plugins/wasm-go/extensions/frontend-gray/main.go index 94d4d8a86..c238b26f4 100644 --- a/plugins/wasm-go/extensions/frontend-gray/main.go +++ b/plugins/wasm-go/extensions/frontend-gray/main.go @@ -44,6 +44,8 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, grayConfig config.GrayConfig, } enabledGray := util.IsGrayEnabled(grayConfig, requestPath) ctx.SetContext(config.EnabledGray, enabledGray) + secFetchMode, _ := proxywasm.GetHttpRequestHeader("sec-fetch-mode") + ctx.SetContext(config.SecFetchMode, secFetchMode) if !enabledGray { log.Infof("gray not enabled") @@ -133,6 +135,10 @@ func onHttpResponseHeader(ctx wrapper.HttpContext, grayConfig config.GrayConfig, ctx.DontReadResponseBody() return types.ActionContinue } + secFetchMode, isSecFetchModeOk := ctx.GetContext(config.SecFetchMode).(string) + if isSecFetchModeOk && secFetchMode == "cors" { + proxywasm.ReplaceHttpResponseHeader("cache-control", "no-cache, no-store, max-age=0, must-revalidate") + } isPageRequest, ok := ctx.GetContext(config.IsPageRequest).(bool) if !ok { isPageRequest = false // 默认值