Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix:【frontend-gray插件】针对fetch的请求,强制不缓存 #1856

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand Down
6 changes: 6 additions & 0 deletions plugins/wasm-go/extensions/frontend-gray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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 // 默认值
Expand Down
Loading