mirror of
https://github.com/alibaba/higress.git
synced 2026-03-10 11:40:49 +08:00
fix ai proxy check request body logic (#1252)
This commit is contained in:
@@ -74,16 +74,16 @@ func onHttpRequestHeader(ctx wrapper.HttpContext, pluginConfig config.PluginConf
|
||||
if handler, ok := activeProvider.(provider.RequestHeadersHandler); ok {
|
||||
// Disable the route re-calculation since the plugin may modify some headers related to the chosen route.
|
||||
ctx.DisableReroute()
|
||||
|
||||
_, err := handler.OnRequestHeaders(ctx, apiName, log)
|
||||
hasRequestBody := wrapper.HasRequestBody()
|
||||
action, err := handler.OnRequestHeaders(ctx, apiName, log)
|
||||
if err == nil {
|
||||
if wrapper.HasRequestBody() {
|
||||
if hasRequestBody {
|
||||
ctx.SetRequestBodyBufferLimit(defaultMaxBodyBytes)
|
||||
// Always return types.HeaderStopIteration to support fallback routing,
|
||||
// as long as onHttpRequestBody can be called.
|
||||
return types.HeaderStopIteration
|
||||
}
|
||||
return types.ActionContinue
|
||||
return action
|
||||
}
|
||||
_ = util.SendResponse(500, "ai-proxy.proc_req_headers_failed", util.MimeTypeTextPlain, fmt.Sprintf("failed to process request headers: %v", err))
|
||||
return types.ActionContinue
|
||||
|
||||
@@ -84,14 +84,19 @@ func IsBinaryResponseBody() bool {
|
||||
}
|
||||
|
||||
func HasRequestBody() bool {
|
||||
contentTypeStr, _ := proxywasm.GetHttpRequestHeader("content-type")
|
||||
contentLengthStr, _ := proxywasm.GetHttpRequestHeader("content-length")
|
||||
transferEncodingStr, _ := proxywasm.GetHttpRequestHeader("transfer-encoding")
|
||||
proxywasm.LogDebugf("check has request body: contentType:%s, contentLengthStr:%s, transferEncodingStr:%s",
|
||||
contentTypeStr, contentLengthStr, transferEncodingStr)
|
||||
if contentTypeStr != "" {
|
||||
return true
|
||||
}
|
||||
if contentLengthStr != "" {
|
||||
contentLength, err := strconv.Atoi(contentLengthStr)
|
||||
if err == nil && contentLength > 0 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
transferEncodingStr, _ := proxywasm.GetHttpRequestHeader("transfer-encoding")
|
||||
return strings.Contains(transferEncodingStr, "chunked")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user