28 lines
771 B
Go
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
|
|
}
|
|
}
|