History

feat(executor): support `$`-based custom headers from downstream request headers

- Propagate request headers into custom-header resolution for OpenAI/Gemini/XAI/Codex execution and websocket flows. - Resolve auth `header:` values like `$ABC` from incoming request headers at request time and omit headers when no value is available. - Add documentation for the dynamic custom-header behavior in `config.example.yaml`.

Luis Pater committed 2 months ago

Commit e424bfa1 parent f3e836c20 files · +646 −59Browse files

Showing the changes to internal/runtime/executor/codex_executor_request.go (1 of 20 files). Show all

Unified · Split

internal/runtime/executor/codex_executor_request.go+10−5
@@ -276,9 +276,11 @@ func codexIdentityConfuseUUID(authID string, kind string, value string) string { · 275 unmodified lines
276276 return uuid.NewSHA1(uuid.NameSpaceOID, []byte(name)).String()
277277 }
278278
279−func applyCodexHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config) {
279+func applyCodexHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config, clientHeaders ...http.Header) {
280280 var ginHeaders http.Header
281− if ginCtx, ok := r.Context().Value("gin").(*gin.Context); ok && ginCtx != nil && ginCtx.Request != nil {
281+ if len(clientHeaders) > 0 && clientHeaders[0] != nil {
282+ ginHeaders = clientHeaders[0]
283+ } else if ginCtx, ok := r.Context().Value("gin").(*gin.Context); ok && ginCtx != nil && ginCtx.Request != nil {
282284 ginHeaders = ginCtx.Request.Header
283285 }
284286 applyCodexHeadersFromSources(r, auth, token, stream, cfg, ginHeaders)
@@ -303,9 +305,12 @@ func applyModelHeaderOverrides(headers http.Header, modelName string) { · 18 unmodified lines
303305
304306 // applyCodexDirectImageHeaders sets Codex upstream headers for direct /images/* calls.
305307 // Downstream client User-Agent values are not forwarded to reduce Cloudflare 1010 blocks.
306−func applyCodexDirectImageHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config) {
308+func applyCodexDirectImageHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config, clientHeaders ...http.Header) {
307309 var ginHeaders http.Header
308− if ginCtx, ok := r.Context().Value("gin").(*gin.Context); ok && ginCtx != nil && ginCtx.Request != nil {
310+ if len(clientHeaders) > 0 && clientHeaders[0] != nil {
311+ ginHeaders = clientHeaders[0].Clone()
312+ ginHeaders.Del("User-Agent")
313+ } else if ginCtx, ok := r.Context().Value("gin").(*gin.Context); ok && ginCtx != nil && ginCtx.Request != nil {
309314 ginHeaders = ginCtx.Request.Header.Clone()
310315 ginHeaders.Del("User-Agent")
311316 }
@@ -359,7 +364,7 @@ func applyCodexHeadersFromSources(r *http.Request, auth *cliproxyauth.Auth, toke · 47 unmodified lines
359364 if auth != nil {
360365 attrs = auth.Attributes
361366 }
362− util.ApplyCustomHeadersFromAttrs(r, attrs)
367+ util.ApplyCustomHeadersFromAttrs(r, attrs, ginHeaders)
363368 applyCodexCloakingHeaders(r.Header, cfg)
364369 }
365370

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t