Skip to content

Commit 1549e4d

Browse files
committed
fix: 🐛 【frontend-gray插件】针对fetch的请求,强制不缓存
1 parent d721c23 commit 1549e4d

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

plugins/wasm-go/extensions/frontend-gray/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const (
1313
IsPageRequest = "is-page-request"
1414
IsNotFound = "is-not-found"
1515
EnabledGray = "enabled-gray"
16+
SecFetchMode = "sec-fetch-mode"
1617
)
1718

1819
type LogInfo func(format string, args ...interface{})

plugins/wasm-go/extensions/frontend-gray/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, grayConfig config.GrayConfig,
4444
}
4545
enabledGray := util.IsGrayEnabled(grayConfig, requestPath)
4646
ctx.SetContext(config.EnabledGray, enabledGray)
47+
secFetchMode, _ := proxywasm.GetHttpRequestHeader("sec-fetch-mode")
48+
ctx.SetContext(config.SecFetchMode, secFetchMode)
4749

4850
if !enabledGray {
4951
log.Infof("gray not enabled")
@@ -133,6 +135,10 @@ func onHttpResponseHeader(ctx wrapper.HttpContext, grayConfig config.GrayConfig,
133135
ctx.DontReadResponseBody()
134136
return types.ActionContinue
135137
}
138+
secFetchMode, isSecFetchModeOk := ctx.GetContext(config.SecFetchMode).(string)
139+
if isSecFetchModeOk && secFetchMode == "cors" {
140+
proxywasm.ReplaceHttpResponseHeader("cache-control", "no-cache, no-store, max-age=0, must-revalidate")
141+
}
136142
isPageRequest, ok := ctx.GetContext(config.IsPageRequest).(bool)
137143
if !ok {
138144
isPageRequest = false // 默认值

0 commit comments

Comments
 (0)