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
276 return uuid.NewSHA1(uuid.NameSpaceOID, []byte(name)).String()276 return uuid.NewSHA1(uuid.NameSpaceOID, []byte(name)).String()
277}277}
278 278
279func applyCodexHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config) {279func applyCodexHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config, clientHeaders ...http.Header) {
280 var ginHeaders http.Header280 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 ginHeaders = ginCtx.Request.Header284 ginHeaders = ginCtx.Request.Header
283 }285 }
284 applyCodexHeadersFromSources(r, auth, token, stream, cfg, ginHeaders)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// applyCodexDirectImageHeaders sets Codex upstream headers for direct /images/* calls.306// applyCodexDirectImageHeaders sets Codex upstream headers for direct /images/* calls.
305// Downstream client User-Agent values are not forwarded to reduce Cloudflare 1010 blocks.307// Downstream client User-Agent values are not forwarded to reduce Cloudflare 1010 blocks.
306func applyCodexDirectImageHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config) {308func applyCodexDirectImageHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, stream bool, cfg *config.Config, clientHeaders ...http.Header) {
307 var ginHeaders http.Header309 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 ginHeaders = ginCtx.Request.Header.Clone()314 ginHeaders = ginCtx.Request.Header.Clone()
310 ginHeaders.Del("User-Agent")315 ginHeaders.Del("User-Agent")
311 }316 }
@@ -359,7 +364,7 @@ func applyCodexHeadersFromSources(r *http.Request, auth *cliproxyauth.Auth, toke · 47 unmodified lines
359 if auth != nil {364 if auth != nil {
360 attrs = auth.Attributes365 attrs = auth.Attributes
361 }366 }
362 util.ApplyCustomHeadersFromAttrs(r, attrs)367 util.ApplyCustomHeadersFromAttrs(r, attrs, ginHeaders)
363 applyCodexCloakingHeaders(r.Header, cfg)368 applyCodexCloakingHeaders(r.Header, cfg)
364}369}
365 370

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