Skip to content

Commit

Permalink
fix: apitoken failover for coze (alibaba#1515)
Browse files Browse the repository at this point in the history
  • Loading branch information
cr7258 authored Nov 18, 2024
1 parent d24123a commit 1b1c08a
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions plugins/wasm-go/extensions/ai-proxy/provider/coze.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}

0 comments on commit 1b1c08a

Please sign in to comment.