fix(codex): conditionally set Session_id header for Mac OS user agents and clean up redundant logic
This commit is contained in:
@@ -29,8 +29,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
codexUserAgent = "codex_cli_rs/0.116.0 (Mac OS 26.0.1; arm64) Apple_Terminal/464"
|
codexUserAgent = "codex-tui/0.118.0 (Mac OS 26.3.1; arm64) iTerm.app/3.6.9 (codex-tui; 0.118.0)"
|
||||||
codexOriginator = "codex_cli_rs"
|
codexOriginator = "codex-tui"
|
||||||
)
|
)
|
||||||
|
|
||||||
var dataTag = []byte("data:")
|
var dataTag = []byte("data:")
|
||||||
@@ -629,7 +629,6 @@ func (e *CodexExecutor) cacheHelper(ctx context.Context, from sdktranslator.Form
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if cache.ID != "" {
|
if cache.ID != "" {
|
||||||
httpReq.Header.Set("Conversation_id", cache.ID)
|
|
||||||
httpReq.Header.Set("Session_id", cache.ID)
|
httpReq.Header.Set("Session_id", cache.ID)
|
||||||
}
|
}
|
||||||
return httpReq, nil
|
return httpReq, nil
|
||||||
@@ -644,13 +643,19 @@ func applyCodexHeaders(r *http.Request, auth *cliproxyauth.Auth, token string, s
|
|||||||
ginHeaders = ginCtx.Request.Header
|
ginHeaders = ginCtx.Request.Header
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ginHeaders.Get("X-Codex-Beta-Features") != "" {
|
||||||
|
r.Header.Set("X-Codex-Beta-Features", ginHeaders.Get("X-Codex-Beta-Features"))
|
||||||
|
}
|
||||||
misc.EnsureHeader(r.Header, ginHeaders, "Version", "")
|
misc.EnsureHeader(r.Header, ginHeaders, "Version", "")
|
||||||
misc.EnsureHeader(r.Header, ginHeaders, "Session_id", uuid.NewString())
|
|
||||||
misc.EnsureHeader(r.Header, ginHeaders, "X-Codex-Turn-Metadata", "")
|
misc.EnsureHeader(r.Header, ginHeaders, "X-Codex-Turn-Metadata", "")
|
||||||
misc.EnsureHeader(r.Header, ginHeaders, "X-Client-Request-Id", "")
|
misc.EnsureHeader(r.Header, ginHeaders, "X-Client-Request-Id", "")
|
||||||
cfgUserAgent, _ := codexHeaderDefaults(cfg, auth)
|
cfgUserAgent, _ := codexHeaderDefaults(cfg, auth)
|
||||||
ensureHeaderWithConfigPrecedence(r.Header, ginHeaders, "User-Agent", cfgUserAgent, codexUserAgent)
|
ensureHeaderWithConfigPrecedence(r.Header, ginHeaders, "User-Agent", cfgUserAgent, codexUserAgent)
|
||||||
|
|
||||||
|
if strings.Contains(r.Header.Get("User-Agent"), "Mac OS") {
|
||||||
|
misc.EnsureHeader(r.Header, ginHeaders, "Session_id", uuid.NewString())
|
||||||
|
}
|
||||||
|
|
||||||
if stream {
|
if stream {
|
||||||
r.Header.Set("Accept", "text/event-stream")
|
r.Header.Set("Accept", "text/event-stream")
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -793,7 +793,6 @@ func applyCodexPromptCacheHeaders(from sdktranslator.Format, req cliproxyexecuto
|
|||||||
if cache.ID != "" {
|
if cache.ID != "" {
|
||||||
rawJSON, _ = sjson.SetBytes(rawJSON, "prompt_cache_key", cache.ID)
|
rawJSON, _ = sjson.SetBytes(rawJSON, "prompt_cache_key", cache.ID)
|
||||||
headers.Set("Conversation_id", cache.ID)
|
headers.Set("Conversation_id", cache.ID)
|
||||||
headers.Set("Session_id", cache.ID)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return rawJSON, headers
|
return rawJSON, headers
|
||||||
@@ -828,9 +827,12 @@ func applyCodexWebsocketHeaders(ctx context.Context, headers http.Header, auth *
|
|||||||
betaHeader = codexResponsesWebsocketBetaHeaderValue
|
betaHeader = codexResponsesWebsocketBetaHeaderValue
|
||||||
}
|
}
|
||||||
headers.Set("OpenAI-Beta", betaHeader)
|
headers.Set("OpenAI-Beta", betaHeader)
|
||||||
misc.EnsureHeader(headers, ginHeaders, "Session_id", uuid.NewString())
|
|
||||||
ensureHeaderWithConfigPrecedence(headers, ginHeaders, "User-Agent", cfgUserAgent, codexUserAgent)
|
ensureHeaderWithConfigPrecedence(headers, ginHeaders, "User-Agent", cfgUserAgent, codexUserAgent)
|
||||||
|
|
||||||
|
if strings.Contains(headers.Get("User-Agent"), "Mac OS") {
|
||||||
|
misc.EnsureHeader(headers, ginHeaders, "Session_id", uuid.NewString())
|
||||||
|
}
|
||||||
|
|
||||||
isAPIKey := false
|
isAPIKey := false
|
||||||
if auth != nil && auth.Attributes != nil {
|
if auth != nil && auth.Attributes != nil {
|
||||||
if v := strings.TrimSpace(auth.Attributes["api_key"]); v != "" {
|
if v := strings.TrimSpace(auth.Attributes["api_key"]); v != "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user