mirror of
https://github.com/alibaba/higress.git
synced 2026-02-06 23:21:08 +08:00
bugfix for model-mapper & model-router (#3370)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -136,11 +137,8 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config) types.Action {
|
||||
break
|
||||
}
|
||||
}
|
||||
if !matched {
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
if !ctx.HasRequestBody() {
|
||||
if !matched || !ctx.HasRequestBody() {
|
||||
ctx.DontReadRequestBody()
|
||||
return types.ActionContinue
|
||||
}
|
||||
@@ -158,6 +156,11 @@ func onHttpRequestBody(ctx wrapper.HttpContext, config Config, body []byte) type
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
if !json.Valid(body) {
|
||||
log.Error("invalid json body")
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
oldModel := gjson.GetBytes(body, config.modelKey).String()
|
||||
|
||||
newModel := config.defaultModel
|
||||
|
||||
@@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"mime"
|
||||
"mime/multipart"
|
||||
@@ -91,15 +92,11 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, config ModelRouterConfig) typ
|
||||
}
|
||||
}
|
||||
|
||||
if !enable {
|
||||
if !enable || !ctx.HasRequestBody() {
|
||||
ctx.DontReadRequestBody()
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
if !ctx.HasRequestBody() {
|
||||
return types.ActionContinue
|
||||
}
|
||||
|
||||
// Prepare for body processing
|
||||
proxywasm.RemoveHttpRequestHeader("content-length")
|
||||
// 100MB buffer limit
|
||||
@@ -124,7 +121,10 @@ func onHttpRequestBody(ctx wrapper.HttpContext, config ModelRouterConfig, body [
|
||||
}
|
||||
|
||||
func handleJsonBody(ctx wrapper.HttpContext, config ModelRouterConfig, body []byte) types.Action {
|
||||
|
||||
if !json.Valid(body) {
|
||||
log.Error("invalid json body")
|
||||
return types.ActionContinue
|
||||
}
|
||||
modelValue := gjson.GetBytes(body, config.modelKey).String()
|
||||
if modelValue == "" {
|
||||
return types.ActionContinue
|
||||
|
||||
Reference in New Issue
Block a user