Skip to content

Commit

Permalink
fix: 🐛 [frontend-gray] 请求非首页资源时候,修复重写路径
Browse files Browse the repository at this point in the history
  • Loading branch information
heimanba committed Sep 27, 2024
1 parent 71aae9d commit 72c25a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 6 additions & 2 deletions plugins/wasm-go/extensions/frontend-gray/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,19 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, grayConfig config.GrayConfig,

// 如果没有配置比例,则进行灰度规则匹配
if isPageRequest {
log.Infof("grayConfig.TotalGrayWeight==== %v", grayConfig.TotalGrayWeight)
if grayConfig.TotalGrayWeight > 0 {
log.Infof("grayConfig.TotalGrayWeight: %v", grayConfig.TotalGrayWeight)
deployment = util.FilterGrayWeight(&grayConfig, preVersion, preUniqueClientId, uniqueClientId)
} else {
deployment = util.FilterGrayRule(&grayConfig, grayKeyValue)
}
log.Infof("index deployment: %v, path: %v, backend: %v, xPreHigressVersion: %s,%s", deployment, path, deployment.BackendVersion, preVersion, preUniqueClientId)
} else {
deployment = util.GetVersion(grayConfig, deployment, preVersion, isPageRequest)
grayDeployment := deployment
if deployment.Version == "" {
grayDeployment = util.FilterGrayRule(&grayConfig, grayKeyValue)
}
deployment = util.GetVersion(grayConfig, grayDeployment, preVersion, isPageRequest)
}
proxywasm.AddHttpRequestHeader(config.XHigressTag, deployment.Version)

Expand Down
18 changes: 9 additions & 9 deletions plugins/wasm-go/extensions/frontend-gray/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func GetVersion(grayConfig config.GrayConfig, deployment *config.Deployment, xPr
}
}
}
return grayConfig.BaseDeployment
return deployment
}

// 从cookie中解析出灰度信息
Expand Down Expand Up @@ -294,12 +294,12 @@ func InjectContent(originalHtml string, injectionConfig *config.Injection) strin

modifiedHtml := sb.String()

// 注入到头部
modifiedHtml = strings.ReplaceAll(modifiedHtml, "</head>", headInjection + "\n</head>")
// 注入到body头
modifiedHtml = strings.ReplaceAll(modifiedHtml, "<body>", "<body>\n" + bodyFirstInjection)
// 注入到body尾
modifiedHtml = strings.ReplaceAll(modifiedHtml, "</body>", bodyLastInjection + "\n</body>")
return modifiedHtml
// 注入到头部
modifiedHtml = strings.ReplaceAll(modifiedHtml, "</head>", headInjection+"\n</head>")
// 注入到body头
modifiedHtml = strings.ReplaceAll(modifiedHtml, "<body>", "<body>\n"+bodyFirstInjection)
// 注入到body尾
modifiedHtml = strings.ReplaceAll(modifiedHtml, "</body>", bodyLastInjection+"\n</body>")

return modifiedHtml
}

0 comments on commit 72c25a4

Please sign in to comment.