mirror of
https://github.com/alibaba/higress.git
synced 2026-03-02 15:40:54 +08:00
Disable reroute in some plugins (#2639)
This commit is contained in:
@@ -60,7 +60,7 @@ builder:
|
||||
@echo "image: ${BUILDER}"
|
||||
|
||||
local-build:
|
||||
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o extensions/${PLUGIN_NAME}/main.wasm extensions/${PLUGIN_NAME}/main.go
|
||||
cd extensions/${PLUGIN_NAME};GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o ./main.wasm ./
|
||||
|
||||
@echo ""
|
||||
@echo "wasm: extensions/${PLUGIN_NAME}/main.wasm"
|
||||
|
||||
@@ -58,6 +58,7 @@ func parseConfig(gjson gjson.Result, c *PluginConfig, log log.Log) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config PluginConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ func parseConfig(json gjson.Result, c *config.PluginConfig, log log.Log) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, c config.PluginConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
skipCache, _ := proxywasm.GetHttpRequestHeader(SKIP_CACHE_HEADER)
|
||||
if skipCache == "on" {
|
||||
ctx.SetContext(SKIP_CACHE_HEADER, struct{}{})
|
||||
|
||||
@@ -170,6 +170,7 @@ func parseConfig(json gjson.Result, c *PluginConfig, log log.Log) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config PluginConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
contentType, _ := proxywasm.GetHttpRequestHeader("content-type")
|
||||
if !strings.Contains(contentType, "application/json") {
|
||||
log.Warnf("content is not json, can't process:%s", contentType)
|
||||
|
||||
@@ -57,6 +57,7 @@ func parseConfig(json gjson.Result, config *Config) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config) types.Action {
|
||||
ctx.DisableReroute()
|
||||
contentType, _ := proxywasm.GetHttpRequestHeader("content-type")
|
||||
if contentType == "" {
|
||||
return types.ActionContinue
|
||||
|
||||
@@ -198,6 +198,7 @@ func parseConfig(json gjson.Result, c *PluginConfig, log log.Log) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config PluginConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
log.Debug("start onHttpRequestHeaders function.")
|
||||
|
||||
log.Debug("end onHttpRequestHeaders function.")
|
||||
|
||||
@@ -449,6 +449,7 @@ func recursiveRefineJson(ctx wrapper.HttpContext, config PluginConfig, log log.L
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config PluginConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
if config.rejectStruct.RejectCode != HTTP_STATUS_OK {
|
||||
sendResponse(ctx, config, log, nil)
|
||||
return types.ActionPause
|
||||
|
||||
@@ -64,6 +64,7 @@ func parseConfig(json gjson.Result, config *Config) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config) types.Action {
|
||||
ctx.DisableReroute()
|
||||
return config.lb.HandleHttpRequestHeaders(ctx)
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ func parseConfig(jsonConfig gjson.Result, config *AIPromptDecoratorConfig, log l
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIPromptDecoratorConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
proxywasm.RemoveHttpRequestHeader("content-length")
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ func parseConfig(json gjson.Result, config *AIPromptTemplateConfig, log log.Log)
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIPromptTemplateConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
templateEnable, _ := proxywasm.GetHttpRequestHeader("template-enable")
|
||||
if templateEnable == "false" {
|
||||
ctx.DontReadRequestBody()
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
"github.com/higress-group/wasm-go/pkg/wrapper"
|
||||
"github.com/tidwall/gjson"
|
||||
"github.com/tidwall/resp"
|
||||
|
||||
|
||||
"github.com/alibaba/higress/plugins/wasm-go/extensions/ai-quota/util"
|
||||
)
|
||||
|
||||
@@ -131,6 +131,7 @@ func parseConfig(json gjson.Result, config *QuotaConfig) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(context wrapper.HttpContext, config QuotaConfig) types.Action {
|
||||
context.DisableReroute()
|
||||
log.Debugf("onHttpRequestHeaders()")
|
||||
// get tokens
|
||||
consumer, err := proxywasm.GetHttpRequestHeader("x-mse-consumer")
|
||||
|
||||
@@ -95,6 +95,7 @@ func parseConfig(json gjson.Result, config *AIRagConfig, log log.Log) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIRagConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
proxywasm.RemoveHttpRequestHeader("content-length")
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
@@ -278,6 +278,7 @@ func parseConfig(json gjson.Result, config *Config) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config) types.Action {
|
||||
ctx.DisableReroute()
|
||||
contentType, _ := proxywasm.GetHttpRequestHeader("content-type")
|
||||
// The request does not have a body.
|
||||
if contentType == "" {
|
||||
|
||||
@@ -254,6 +254,7 @@ func generateRandomID() string {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AISecurityConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
if !config.checkRequest {
|
||||
log.Debugf("request checking is disabled")
|
||||
ctx.DontReadRequestBody()
|
||||
|
||||
@@ -175,6 +175,7 @@ func parseConfig(configJson gjson.Result, config *AIStatisticsConfig) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIStatisticsConfig) types.Action {
|
||||
ctx.DisableReroute()
|
||||
route, _ := getRouteName()
|
||||
cluster, _ := getClusterName()
|
||||
api, apiError := getAPIName()
|
||||
@@ -191,11 +192,8 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config AIStatisticsConfig) ty
|
||||
if consumer, _ := proxywasm.GetHttpRequestHeader(ConsumerKey); consumer != "" {
|
||||
ctx.SetContext(ConsumerKey, consumer)
|
||||
}
|
||||
hasRequestBody := wrapper.HasRequestBody()
|
||||
if hasRequestBody {
|
||||
_ = proxywasm.RemoveHttpRequestHeader("Content-Length")
|
||||
ctx.SetRequestBodyBufferLimit(defaultMaxBodyBytes)
|
||||
}
|
||||
|
||||
ctx.SetRequestBodyBufferLimit(defaultMaxBodyBytes)
|
||||
|
||||
// Set user defined log & span attributes which type is fixed_value
|
||||
setAttributeBySource(ctx, config, FixedValue, nil)
|
||||
|
||||
@@ -99,6 +99,7 @@ func parseConfig(json gjson.Result, config *ClusterKeyRateLimitConfig) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config ClusterKeyRateLimitConfig) types.Action {
|
||||
ctx.DisableReroute()
|
||||
// 判断是否命中限流规则
|
||||
val, ruleItem, configItem := checkRequestAgainstLimitRule(ctx, config.ruleItems)
|
||||
if ruleItem == nil || configItem == nil {
|
||||
|
||||
@@ -93,6 +93,7 @@ func extraceHttpFrame(frame string) ([][2]string, []byte, error) {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config AITransformerConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
log.Info("onHttpRequestHeaders")
|
||||
if !config.requestTransformEnable || config.requestTransformPrompt == "" {
|
||||
ctx.DontReadRequestBody()
|
||||
|
||||
@@ -87,6 +87,7 @@ func parseConfig(json gjson.Result, cfg *config.ClusterKeyRateLimitConfig) error
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config config.ClusterKeyRateLimitConfig) types.Action {
|
||||
ctx.DisableReroute()
|
||||
limitKey, count, timeWindow := "", int64(0), int64(0)
|
||||
|
||||
if config.GlobalThreshold != nil {
|
||||
|
||||
@@ -75,6 +75,7 @@ func parseConfig(json gjson.Result, corsConfig *config.CorsConfig, log log.Log)
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, corsConfig config.CorsConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
log.Debug("onHttpRequestHeaders()")
|
||||
requestUrl, _ := proxywasm.GetHttpRequestHeader(":path")
|
||||
method, _ := proxywasm.GetHttpRequestHeader(":method")
|
||||
|
||||
@@ -61,6 +61,7 @@ func parseConfig(json gjson.Result, config *config.DeGraphQLConfig, log log.Log)
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config config.DeGraphQLConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
log.Debug("onHttpRequestHeaders()")
|
||||
log.Debugf("schema:%s host:%s path:%s", ctx.Scheme(), ctx.Host(), ctx.Path())
|
||||
requestUrl, _ := proxywasm.GetHttpRequestHeader(":path")
|
||||
|
||||
@@ -204,6 +204,7 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config GeoIpConfig, log log.L
|
||||
s string
|
||||
err error
|
||||
)
|
||||
ctx.DisableReroute()
|
||||
if config.IPSourceType == HeaderSourceType {
|
||||
s, err = proxywasm.GetHttpRequestHeader(config.IPHeaderName)
|
||||
if err == nil {
|
||||
|
||||
@@ -59,6 +59,7 @@ func parseConfig(json gjson.Result, config *PluginConfig, log log.Log) error {
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config PluginConfig, log log.Log) types.Action {
|
||||
ctx.DisableReroute()
|
||||
config.oidcHandler.SetContext(ctx)
|
||||
req := getHttpRequest()
|
||||
rw := util.NewRecorder()
|
||||
|
||||
@@ -15,7 +15,6 @@ require (
|
||||
|
||||
require (
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/higress-group/wasm-go v1.0.2-0.20250715122353-fca24464ab2d // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20250611100342-5654e89a7a80 h1:xqmtTZI0JQ2O+Lg9/CE6c+Tw9KD6FnvWw8EpLVuuvfg=
|
||||
github.com/higress-group/proxy-wasm-go-sdk v0.0.0-20250611100342-5654e89a7a80/go.mod h1:tRI2LfMudSkKHhyv1uex3BWzcice2s/l8Ah8axporfA=
|
||||
github.com/higress-group/wasm-go v1.0.2-0.20250715122353-fca24464ab2d h1:abvhxCCNJgQij0IvRvuLnudjAPXwfuv2+d9WZwkACNQ=
|
||||
github.com/higress-group/wasm-go v1.0.2-0.20250715122353-fca24464ab2d/go.mod h1:9k7L730huS/q4V5iH9WLDgf5ZUHEtfhM/uXcegKDG/M=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.17.3 h1:bwWLZU7icoKRG+C+0PNwIKC6FCJO/Q3p2pZvuP0jN94=
|
||||
github.com/tidwall/gjson v1.17.3/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
||||
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/resp v0.1.1 h1:Ly20wkhqKTmDUPlyM1S7pWo5kk0tDu8OoC/vFArXmwE=
|
||||
github.com/tidwall/resp v0.1.1/go.mod h1:3/FrruOBAxPTPtundW0VXgmsQ4ZBA0Aw714lVYgwFa0=
|
||||
|
||||
Reference in New Issue
Block a user