Skip to content

Commit 3ab0166

Browse files
committed
fix: Carry verification Token in Header issue #3
1 parent 66d5080 commit 3ab0166

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

models/gemini/model.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
type RequestConverter interface {
1313
Name() string
14-
Convert(req *http.Request, config *define.ModelConfig, payload []byte, openaiPayload define.OpenAI_Payload) (*http.Request, error)
14+
Convert(req *http.Request, config *define.ModelConfig, payload []byte, openaiPayload define.OpenAI_Payload, apikey string) (*http.Request, error)
1515
}
1616

1717
type StripPrefixConverter struct {
@@ -22,7 +22,7 @@ func (c *StripPrefixConverter) Name() string {
2222
return "StripPrefix"
2323
}
2424

25-
func (c *StripPrefixConverter) Convert(req *http.Request, config *define.ModelConfig, payload []byte, openaiPayload define.OpenAI_Payload) (*http.Request, error) {
25+
func (c *StripPrefixConverter) Convert(req *http.Request, config *define.ModelConfig, payload []byte, openaiPayload define.OpenAI_Payload, apikey string) (*http.Request, error) {
2626
req.Host = config.URL.Host
2727
req.URL.Scheme = config.URL.Scheme
2828
req.URL.Host = config.URL.Host
@@ -36,7 +36,15 @@ func (c *StripPrefixConverter) Convert(req *http.Request, config *define.ModelCo
3636
req.URL.RawPath = req.URL.EscapedPath()
3737

3838
query := req.URL.Query()
39-
query.Add("key", config.Key)
39+
if config.Key == "" {
40+
if apikey == "" {
41+
return nil, fmt.Errorf("missing api key")
42+
} else {
43+
query.Add("key", apikey)
44+
}
45+
} else {
46+
query.Add("key", config.Key)
47+
}
4048
req.URL.RawQuery = query.Encode()
4149
req.Body = io.NopCloser(bytes.NewBuffer(payload))
4250
req.ContentLength = int64(len(payload))

models/gemini/proxy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func getDirector(req *http.Request, body []byte, c *gin.Context, requestConverte
126126
network.SendError(c, errors.New("token is empty"))
127127
return
128128
}
129-
req.Header.Set("Authorization", token)
129+
req.Header.Del("Authorization")
130130

131131
repack, err := json.Marshal(payload)
132132
if err != nil {
@@ -135,7 +135,7 @@ func getDirector(req *http.Request, body []byte, c *gin.Context, requestConverte
135135
}
136136

137137
originURL := req.URL.String()
138-
req, err = requestConverter.Convert(req, deployment, repack, openaiPayload)
138+
req, err = requestConverter.Convert(req, deployment, repack, openaiPayload, token)
139139
if err != nil {
140140
network.SendError(c, errors.Wrap(err, "convert request error"))
141141
return

0 commit comments

Comments
 (0)