bugfix for model-mapper & model-router (#3370)

This commit is contained in:
rinfx
2026-01-28 10:52:45 +08:00
committed by GitHub
parent a92c89ce61
commit cbcc3ecf43
2 changed files with 13 additions and 10 deletions

View File

@@ -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

View File

@@ -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