feat: header passthrough - #2735
Conversation
WalkthroughAdds runtime placeholder resolution for header overrides ({api_key}, {client_header:}) via a new helper. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Handler as API Handler (DoApiRequest / DoFormRequest / DoWssRequest)
participant Processor as processHeaderOverride
participant Resolver as applyHeaderOverridePlaceholders
participant OutReq as Outgoing Request
Client->>Handler: Incoming request + gin.Context
Handler->>Processor: processHeaderOverride(info, gin.Context)
Processor->>Resolver: applyHeaderOverridePlaceholders(template, gin.Context, apiKey)
rect rgba(100, 150, 200, 0.5)
Note over Resolver: Parse {api_key} and {client_header:<name>}<br/>Validate syntax & context, then substitute runtime values
end
Resolver-->>Processor: resolvedValue + includeFlag
alt includeFlag == true
Processor->>OutReq: add header with resolvedValue
else
Processor->>OutReq: omit header
end
OutReq-->>Client: response
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly Related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@relay/channel/api_request.go`:
- Around line 41-73: The applyHeaderOverridePlaceholders function currently
performs {api_key} interpolation after handling a {client_header:...}
placeholder, allowing a client-supplied header to include "{api_key}" and leak
the key; modify applyHeaderOverridePlaceholders so that when a client header
placeholder is detected (strings.HasPrefix(trimmed,
clientHeaderPlaceholderPrefix)) and a non-empty clientHeaderValue is obtained,
the function returns immediately with that value (return template, true, nil)
instead of continuing to the {api_key} replacement logic; update the branch that
sets template = clientHeaderValue in applyHeaderOverridePlaceholders to return
early and keep existing error/empty-value behavior unchanged.
# Conflicts: # relay/channel/api_request.go
…ughpass feat: header passthrough
请求头透传
使用方式 :
{
anthropic-version: {client_header:anthropic-version}
}
先在后端进行更改,后续会采用 #2365 的部分前端变更作为UI编辑页
Summary by CodeRabbit
New Features
Bug Fixes / Reliability
✏️ Tip: You can customize this high-level summary in your review settings.