From 1b1c08afb7d505eeeba41aef0421e4a4e32c0c4f Mon Sep 17 00:00:00 2001 From: Se7en Date: Mon, 18 Nov 2024 15:36:26 +0800 Subject: [PATCH] fix: apitoken failover for coze (#1515) --- plugins/wasm-go/extensions/ai-proxy/provider/coze.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/wasm-go/extensions/ai-proxy/provider/coze.go b/plugins/wasm-go/extensions/ai-proxy/provider/coze.go index c163c95661..878bbb9f9a 100644 --- a/plugins/wasm-go/extensions/ai-proxy/provider/coze.go +++ b/plugins/wasm-go/extensions/ai-proxy/provider/coze.go @@ -2,6 +2,7 @@ package provider import ( "errors" + "net/http" "github.com/alibaba/higress/plugins/wasm-go/extensions/ai-proxy/util" "github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper" @@ -38,7 +39,12 @@ func (m *cozeProvider) GetProviderType() string { } func (m *cozeProvider) OnRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, log wrapper.Log) (types.Action, error) { - _ = util.OverwriteRequestHost(cozeDomain) - _ = util.OverwriteRequestAuthorization("Bearer " + m.config.GetRandomToken()) + m.config.handleRequestHeaders(m, ctx, apiName, log) return types.ActionContinue, nil } + +func (m *cozeProvider) TransformRequestHeaders(ctx wrapper.HttpContext, apiName ApiName, headers http.Header, log wrapper.Log) { + util.OverwriteRequestHostHeader(headers, cozeDomain) + util.OverwriteRequestAuthorizationHeader(headers, "Bearer "+m.config.GetApiTokenInUse(ctx)) + headers.Del("Content-Length") +}