mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-20 15:06:36 +00:00
fix(openai): pair originator with final User-Agent for codex upstream
上游 /backend-api/codex 的 404 gating 是配套校验:originator 必须与 User-Agent 首段(首个 '/' 前的 client 名)配套且为官方 codex 身份, 错配(如 originator=codex_cli_rs + UA=codex-tui/...)一律 404;version 头若携带须 >= 0.144.0。 修复: - pkg/openai 新增 PairCodexClientIdentity:由最终出站 UA 推导配套 originator(含 CODEX_INTERNAL_ORIGINATOR_OVERRIDE 尾部括号组身份恢复、 精确集合大小写归一、长度/字符集校验) - service 新增 enforceCodexIdentityHeaders 终态收口:originator 按最终 UA 重配,推导不出官方身份整体回退默认 Codex CLI 身份;version 低于 0.144.0 提升为内置版本;originator 缺失时 no-op(保护 messages bridge) - 接入非透传/透传/WS 三条转发路径(透传与 WS 删除会把 codex-tui 等官方 UA 强改为 codex_cli_rs 造成错配的旧兜底)、用量探针(指纹缓存 UA 与硬 编码 originator 错配)、账号 responses/图像测试(opencode 错配) - messages 兼容桥构建前显式打 bridge 标记,防止映射到非 gpt-5/codex 模型时收口误改其刻意最小化的请求形态 Fixes #3901
This commit is contained in:
1 parent
5260a42a0b
commit
8a51119e39
13 files changed
+406
-18
No files matched your search
@@ -944,6 +944,11 @@ func (s *OpenAIGatewayService) buildUpstreamRequest(ctx context.Context, c *gin.
|
||||
// (Chrome/Firefox/Safari/Edge 等),替换为后台配置的 Codex UA,避免 Cloudflare 触发 JS 质询。
|
||||
s.overrideBrowserUserAgent(ctx, account, req)
|
||||
|
||||
// 终态收口:originator 必须与最终 User-Agent 首段配套且为官方身份,否则上游 404(issue #3901)。
|
||||
if account.Type == AccountTypeOAuth {
|
||||
enforceCodexIdentityHeaders(req.Header)
|
||||
}
|
||||
|
||||
// Ensure required headers exist
|
||||
if req.Header.Get("content-type") == "" {
|
||||
req.Header.Set("content-type", "application/json")
|
||||
|
||||
Reference in new issue
Block a user