fix: add nil guard for gin.Context in header passthrough to satisfy staticcheck SA5011
This commit is contained in:
@@ -3492,6 +3492,7 @@ func (s *AntigravityGatewayService) ForwardUpstream(ctx context.Context, c *gin.
|
|||||||
return nil, s.writeClaudeError(c, http.StatusInternalServerError, "api_error", "Failed to build request")
|
return nil, s.writeClaudeError(c, http.StatusInternalServerError, "api_error", "Failed to build request")
|
||||||
}
|
}
|
||||||
// 透传客户端所有请求头(排除 hop-by-hop 和认证头)
|
// 透传客户端所有请求头(排除 hop-by-hop 和认证头)
|
||||||
|
if c != nil && c.Request != nil {
|
||||||
for key, values := range c.Request.Header {
|
for key, values := range c.Request.Header {
|
||||||
if upstreamHopByHopHeaders[strings.ToLower(key)] {
|
if upstreamHopByHopHeaders[strings.ToLower(key)] {
|
||||||
continue
|
continue
|
||||||
@@ -3500,6 +3501,7 @@ func (s *AntigravityGatewayService) ForwardUpstream(ctx context.Context, c *gin.
|
|||||||
req.Header.Add(key, v)
|
req.Header.Add(key, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 覆盖认证头
|
// 覆盖认证头
|
||||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
req.Header.Set("x-api-key", apiKey)
|
req.Header.Set("x-api-key", apiKey)
|
||||||
@@ -3638,6 +3640,7 @@ func (s *AntigravityGatewayService) ForwardUpstreamGemini(ctx context.Context, c
|
|||||||
return nil, s.writeGoogleError(c, http.StatusInternalServerError, "Failed to build request")
|
return nil, s.writeGoogleError(c, http.StatusInternalServerError, "Failed to build request")
|
||||||
}
|
}
|
||||||
// 透传客户端所有请求头(排除 hop-by-hop 和认证头)
|
// 透传客户端所有请求头(排除 hop-by-hop 和认证头)
|
||||||
|
if c != nil && c.Request != nil {
|
||||||
for key, values := range c.Request.Header {
|
for key, values := range c.Request.Header {
|
||||||
if upstreamHopByHopHeaders[strings.ToLower(key)] {
|
if upstreamHopByHopHeaders[strings.ToLower(key)] {
|
||||||
continue
|
continue
|
||||||
@@ -3646,6 +3649,7 @@ func (s *AntigravityGatewayService) ForwardUpstreamGemini(ctx context.Context, c
|
|||||||
req.Header.Add(key, v)
|
req.Header.Add(key, v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// 覆盖认证头
|
// 覆盖认证头
|
||||||
req.Header.Set("Authorization", "Bearer "+apiKey)
|
req.Header.Set("Authorization", "Bearer "+apiKey)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user