Skip to content

Commit 2501895

Browse files
authored
ai-cache update body buffer limit size (#1644)
1 parent 187a7b5 commit 2501895

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

plugins/wasm-go/extensions/ai-cache/main.go

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ const (
2222
STREAM_CONTEXT_KEY = "stream"
2323
SKIP_CACHE_HEADER = "x-higress-skip-ai-cache"
2424
ERROR_PARTIAL_MESSAGE_KEY = "errorPartialMessage"
25+
26+
DEFAULT_MAX_BODY_BYTES uint32 = 10 * 1024 * 1024
2527
)
2628

2729
func main() {
@@ -69,6 +71,7 @@ func onHttpRequestHeaders(ctx wrapper.HttpContext, c config.PluginConfig, log wr
6971
ctx.DontReadRequestBody()
7072
return types.ActionContinue
7173
}
74+
ctx.SetRequestBodyBufferLimit(DEFAULT_MAX_BODY_BYTES)
7275
_ = proxywasm.RemoveHttpRequestHeader("Accept-Encoding")
7376
// The request has a body and requires delaying the header transmission until a cache miss occurs,
7477
// at which point the header should be sent.
@@ -140,6 +143,8 @@ func onHttpResponseHeaders(ctx wrapper.HttpContext, c config.PluginConfig, log w
140143
contentType, _ := proxywasm.GetHttpResponseHeader("content-type")
141144
if strings.Contains(contentType, "text/event-stream") {
142145
ctx.SetContext(STREAM_CONTEXT_KEY, struct{}{})
146+
} else {
147+
ctx.SetResponseBodyBufferLimit(DEFAULT_MAX_BODY_BYTES)
143148
}
144149

145150
if ctx.GetContext(ERROR_PARTIAL_MESSAGE_KEY) != nil {

plugins/wasm-go/extensions/ai-proxy/main.go

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ func checkStream(ctx *wrapper.HttpContext, log wrapper.Log) {
261261
log.Errorf("unable to load content-type header from response: %v", err)
262262
}
263263
(*ctx).BufferResponseBody()
264+
ctx.SetResponseBodyBufferLimit(defaultMaxBodyBytes)
264265
}
265266
}
266267

plugins/wasm-go/pkg/wrapper/plugin_wrapper.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ type HttpContext interface {
6565
// You need to call this before making any header modification operations.
6666
DisableReroute()
6767
// Note that this parameter affects the gateway's memory usage!Support setting a maximum buffer size for each request body individually in request phase.
68-
SetRequestBodyBufferLimit(size uint32)
68+
SetRequestBodyBufferLimit(byteSize uint32)
6969
// Note that this parameter affects the gateway's memory usage! Support setting a maximum buffer size for each response body individually in response phase.
70-
SetResponseBodyBufferLimit(size uint32)
70+
SetResponseBodyBufferLimit(byteSize uint32)
7171
}
7272

7373
type ParseConfigFunc[PluginConfig any] func(json gjson.Result, config *PluginConfig, log Log) error

0 commit comments

Comments
 (0)