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