From 96d3fc762afe31f74370782726a5e461af7af737 Mon Sep 17 00:00:00 2001 From: tbphp Date: Sun, 29 Jun 2025 09:26:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=B8=8A=E6=B8=B8=E6=94=AF=E6=8C=81gem?= =?UTF-8?q?ini=E6=A0=BC=E5=BC=8F=E9=80=8F=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/proxy/server.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/internal/proxy/server.go b/internal/proxy/server.go index e81e122..28a1256 100644 --- a/internal/proxy/server.go +++ b/internal/proxy/server.go @@ -259,8 +259,20 @@ func (ps *ProxyServer) executeRequestWithRetry(c *gin.Context, startTime time.Ti } } - // Set authorization header - req.Header.Set("Authorization", "Bearer "+keyInfo.Key) + if c.GetHeader("Authorization") != "" { + req.Header.Set("Authorization", "Bearer "+keyInfo.Key) + req.Header.Del("X-Goog-Api-Key") + } else if c.GetHeader("X-Goog-Api-Key") != "" || c.Query("key") != "" { + req.Header.Set("X-Goog-Api-Key", keyInfo.Key) + req.Header.Del("Authorization") + } else { + c.JSON(http.StatusUnauthorized, gin.H{ + "error": "API key required. Please provide a key in 'Authorization' or 'X-Goog-Api-Key' header.", + "code": errors.ErrAuthMissing, + }) + c.Abort() + return + } // Choose appropriate client based on request type var client *http.Client