fix: sync codex field (#6018)

This commit is contained in:
Seefs
2026-07-11 11:04:15 +08:00
committed by GitHub
parent 00f1cbb6df
commit dad57a6bb8
9 changed files with 162 additions and 14 deletions
+20
View File
@@ -14,6 +14,7 @@ import (
"github.com/QuantumNous/new-api/constant"
"github.com/QuantumNous/new-api/logger"
relaycommon "github.com/QuantumNous/new-api/relay/common"
"github.com/QuantumNous/new-api/service"
"github.com/QuantumNous/new-api/setting/operation_setting"
"github.com/bytedance/gopkg/util/gopool"
@@ -45,6 +46,24 @@ func NewStreamScanner(reader io.Reader) *bufio.Scanner {
return scanner
}
func copyCodexSSEHeaders(c *gin.Context, resp *http.Response) {
if c == nil || c.Writer == nil || resp == nil {
return
}
// codex
for _, name := range []string{"X-Reasoning-Included", "X-Codex-Turn-State"} {
values := resp.Header.Values(name)
if !service.ShouldCopyUpstreamHeader(c, name, values) {
continue
}
for _, value := range values {
if value != "" {
c.Writer.Header().Add(name, value)
}
}
}
}
// ExtendWriteDeadline pushes the connection write deadline forward before each
// stream write. Best-effort: writers that don't support deadlines (e.g.
// httptest recorders) are silently ignored.
@@ -122,6 +141,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
defer cleanup()
scanner.Split(bufio.ScanLines)
copyCodexSSEHeaders(c, resp)
SetEventStreamHeaders(c)
ctx = context.WithValue(ctx, "stop_chan", stopChan)