Initial commit
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user