mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-03 04:50:52 +08:00
- 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.
25 lines
431 B
Go
25 lines
431 B
Go
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)
|
|
}
|
|
}
|