@@ -190,7 +190,7 @@ func (e *CodexWebsocketsExecutor) Execute(ctx context.Context, auth *cliproxyaut
190190 }
191191
192192 body , wsHeaders := applyCodexPromptCacheHeaders (from , req , body )
193- wsHeaders = applyCodexWebsocketHeaders (ctx , wsHeaders , auth , apiKey )
193+ wsHeaders = applyCodexWebsocketHeaders (ctx , wsHeaders , auth , apiKey , e . cfg )
194194
195195 var authID , authLabel , authType , authValue string
196196 if auth != nil {
@@ -385,7 +385,7 @@ func (e *CodexWebsocketsExecutor) ExecuteStream(ctx context.Context, auth *clipr
385385 }
386386
387387 body , wsHeaders := applyCodexPromptCacheHeaders (from , req , body )
388- wsHeaders = applyCodexWebsocketHeaders (ctx , wsHeaders , auth , apiKey )
388+ wsHeaders = applyCodexWebsocketHeaders (ctx , wsHeaders , auth , apiKey , e . cfg )
389389
390390 var authID , authLabel , authType , authValue string
391391 authID = auth .ID
@@ -787,7 +787,7 @@ func applyCodexPromptCacheHeaders(from sdktranslator.Format, req cliproxyexecuto
787787 return rawJSON , headers
788788}
789789
790- func applyCodexWebsocketHeaders (ctx context.Context , headers http.Header , auth * cliproxyauth.Auth , token string ) http.Header {
790+ func applyCodexWebsocketHeaders (ctx context.Context , headers http.Header , auth * cliproxyauth.Auth , token string , cfg * config. Config ) http.Header {
791791 if headers == nil {
792792 headers = http.Header {}
793793 }
@@ -800,7 +800,8 @@ func applyCodexWebsocketHeaders(ctx context.Context, headers http.Header, auth *
800800 ginHeaders = ginCtx .Request .Header
801801 }
802802
803- misc .EnsureHeader (headers , ginHeaders , "x-codex-beta-features" , "" )
803+ cfgUserAgent , cfgBetaFeatures := codexHeaderDefaults (cfg , auth )
804+ ensureHeaderWithPriority (headers , ginHeaders , "x-codex-beta-features" , cfgBetaFeatures , "" )
804805 misc .EnsureHeader (headers , ginHeaders , "x-codex-turn-state" , "" )
805806 misc .EnsureHeader (headers , ginHeaders , "x-codex-turn-metadata" , "" )
806807 misc .EnsureHeader (headers , ginHeaders , "x-responsesapi-include-timing-metrics" , "" )
@@ -815,7 +816,7 @@ func applyCodexWebsocketHeaders(ctx context.Context, headers http.Header, auth *
815816 }
816817 headers .Set ("OpenAI-Beta" , betaHeader )
817818 misc .EnsureHeader (headers , ginHeaders , "Session_id" , uuid .NewString ())
818- misc . EnsureHeader (headers , ginHeaders , "User-Agent" , codexUserAgent )
819+ ensureHeaderWithConfigPrecedence (headers , ginHeaders , "User-Agent" , cfgUserAgent , codexUserAgent )
819820
820821 isAPIKey := false
821822 if auth != nil && auth .Attributes != nil {
@@ -843,6 +844,62 @@ func applyCodexWebsocketHeaders(ctx context.Context, headers http.Header, auth *
843844 return headers
844845}
845846
847+ func codexHeaderDefaults (cfg * config.Config , auth * cliproxyauth.Auth ) (string , string ) {
848+ if cfg == nil || auth == nil {
849+ return "" , ""
850+ }
851+ if auth .Attributes != nil {
852+ if v := strings .TrimSpace (auth .Attributes ["api_key" ]); v != "" {
853+ return "" , ""
854+ }
855+ }
856+ return strings .TrimSpace (cfg .CodexHeaderDefaults .UserAgent ), strings .TrimSpace (cfg .CodexHeaderDefaults .BetaFeatures )
857+ }
858+
859+ func ensureHeaderWithPriority (target http.Header , source http.Header , key , configValue , fallbackValue string ) {
860+ if target == nil {
861+ return
862+ }
863+ if strings .TrimSpace (target .Get (key )) != "" {
864+ return
865+ }
866+ if source != nil {
867+ if val := strings .TrimSpace (source .Get (key )); val != "" {
868+ target .Set (key , val )
869+ return
870+ }
871+ }
872+ if val := strings .TrimSpace (configValue ); val != "" {
873+ target .Set (key , val )
874+ return
875+ }
876+ if val := strings .TrimSpace (fallbackValue ); val != "" {
877+ target .Set (key , val )
878+ }
879+ }
880+
881+ func ensureHeaderWithConfigPrecedence (target http.Header , source http.Header , key , configValue , fallbackValue string ) {
882+ if target == nil {
883+ return
884+ }
885+ if strings .TrimSpace (target .Get (key )) != "" {
886+ return
887+ }
888+ if val := strings .TrimSpace (configValue ); val != "" {
889+ target .Set (key , val )
890+ return
891+ }
892+ if source != nil {
893+ if val := strings .TrimSpace (source .Get (key )); val != "" {
894+ target .Set (key , val )
895+ return
896+ }
897+ }
898+ if val := strings .TrimSpace (fallbackValue ); val != "" {
899+ target .Set (key , val )
900+ }
901+ }
902+
846903type statusErrWithHeaders struct {
847904 statusErr
848905 headers http.Header
0 commit comments