mirror of
https://github.com/alibaba/higress.git
synced 2026-05-27 22:27:29 +08:00
bugfix:【frontend-gray插件】针对fetch的请求,强制不缓存 (#1856)
This commit is contained in:
@@ -13,6 +13,7 @@ const (
|
|||||||
IsPageRequest = "is-page-request"
|
IsPageRequest = "is-page-request"
|
||||||
IsNotFound = "is-not-found"
|
IsNotFound = "is-not-found"
|
||||||
EnabledGray = "enabled-gray"
|
EnabledGray = "enabled-gray"
|
||||||
|
SecFetchMode = "sec-fetch-mode"
|
||||||
)
|
)
|
||||||
|
|
||||||
type LogInfo func(format string, args ...interface{})
|
type LogInfo func(format string, args ...interface{})
|
||||||
|
|||||||
@@ -44,6 +44,8 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, grayConfig config.GrayConfig,
|
|||||||
}
|
}
|
||||||
enabledGray := util.IsGrayEnabled(grayConfig, requestPath)
|
enabledGray := util.IsGrayEnabled(grayConfig, requestPath)
|
||||||
ctx.SetContext(config.EnabledGray, enabledGray)
|
ctx.SetContext(config.EnabledGray, enabledGray)
|
||||||
|
secFetchMode, _ := proxywasm.GetHttpRequestHeader("sec-fetch-mode")
|
||||||
|
ctx.SetContext(config.SecFetchMode, secFetchMode)
|
||||||
|
|
||||||
if !enabledGray {
|
if !enabledGray {
|
||||||
log.Infof("gray not enabled")
|
log.Infof("gray not enabled")
|
||||||
@@ -133,6 +135,10 @@ func onHttpResponseHeader(ctx wrapper.HttpContext, grayConfig config.GrayConfig,
|
|||||||
ctx.DontReadResponseBody()
|
ctx.DontReadResponseBody()
|
||||||
return types.ActionContinue
|
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)
|
isPageRequest, ok := ctx.GetContext(config.IsPageRequest).(bool)
|
||||||
if !ok {
|
if !ok {
|
||||||
isPageRequest = false // 默认值
|
isPageRequest = false // 默认值
|
||||||
|
|||||||
Reference in New Issue
Block a user