- 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`.
Showing the changes to internal/runtime/executor/codex_executor_request.go (1 of 20 files). Show all
Unified · Split
| @@ -276,9 +276,11 @@ func codexIdentityConfuseUUID(authID string, kind string, value string) string { · 275 unmodified lines | ||
| 276 | 276 | return uuid.NewSHA1(uuid.NameSpaceOID, []byte(name)).String() |
| 277 | 277 | } |
| 278 | 278 | |
| 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) { | |
| 280 | 280 | 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 { | |
| 282 | 284 | ginHeaders = ginCtx.Request.Header |
| 283 | 285 | } |
| 284 | 286 | applyCodexHeadersFromSources(r, auth, token, stream, cfg, ginHeaders) |
| @@ -303,9 +305,12 @@ func applyModelHeaderOverrides(headers http.Header, modelName string) { · 18 unmodified lines | ||
| 303 | 305 | |
| 304 | 306 | // applyCodexDirectImageHeaders sets Codex upstream headers for direct /images/* calls. |
| 305 | 307 | // 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) { | |
| 307 | 309 | 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 { | |
| 309 | 314 | ginHeaders = ginCtx.Request.Header.Clone() |
| 310 | 315 | ginHeaders.Del("User-Agent") |
| 311 | 316 | } |
| @@ -359,7 +364,7 @@ func applyCodexHeadersFromSources(r *http.Request, auth *cliproxyauth.Auth, toke · 47 unmodified lines | ||
| 359 | 364 | if auth != nil { |
| 360 | 365 | attrs = auth.Attributes |
| 361 | 366 | } |
| 362 | − util.ApplyCustomHeadersFromAttrs(r, attrs) | |
| 367 | + util.ApplyCustomHeadersFromAttrs(r, attrs, ginHeaders) | |
| 363 | 368 | applyCodexCloakingHeaders(r.Header, cfg) |
| 364 | 369 | } |
| 365 | 370 | |