fix ai proxy check request body logic (#1252)

This commit is contained in:
澄潭
2024-08-26 13:33:44 +08:00
committed by GitHub
parent a64cb172bf
commit 496346fe95
2 changed files with 11 additions and 6 deletions

View File

@@ -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")
}