refactor(headers): centralize header logic using EnsureHeader utility

- Introduced `EnsureHeader` in `internal/misc/header_utils.go` to streamline header setting across executors.
- Updated Codex, Claude, and Gemini executors to utilize `EnsureHeader` for consistent header application.
- Incorporated Gin context headers (if available) into request header manipulation for better integration.
This commit is contained in:
Luis Pater
2025-09-23 02:01:57 +08:00
parent 7ea88358f0
commit d32fc0400e
4 changed files with 68 additions and 22 deletions

View File

@@ -0,0 +1,24 @@
package misc
import (
"net/http"
"strings"
)
func EnsureHeader(target http.Header, source http.Header, key, defaultValue string) {
if target == nil {
return
}
if source != nil {
if val := strings.TrimSpace(source.Get(key)); val != "" {
target.Set(key, val)
return
}
}
if strings.TrimSpace(target.Get(key)) != "" {
return
}
if val := strings.TrimSpace(defaultValue); val != "" {
target.Set(key, val)
}
}