Files
fish03andClaude Opus 5.5 bef9f8b4ed Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-09-23 14:43:16 +07:00

28 lines
771 B
Go

package http
import "strings"
// ApplyClientForwardHeaders 向上游透传客户端 IP 与浏览器 UA。
func ApplyClientForwardHeaders(header map[string]string, clientIP, userAgent string) {
if header == nil {
return
}
if ip := strings.TrimSpace(clientIP); ip != "" {
header["X-Real-IP"] = ip
}
if ua := strings.TrimSpace(userAgent); ua != "" {
header["User-Agent"] = ua
}
}
// ApplyClientForwardHeadersWithXUA 透传 IP、浏览器 UA,以及可选的 X-User-Agent。
func ApplyClientForwardHeadersWithXUA(header map[string]string, clientIP, userAgent, xUserAgent string) {
ApplyClientForwardHeaders(header, clientIP, userAgent)
if header == nil {
return
}
if xua := strings.TrimSpace(xUserAgent); xua != "" {
header["X-User-Agent"] = xua
}
}