mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-12 14:30:54 +08:00
X-Forwarded-For中包含当前客户端的IP
This commit is contained in:
@@ -1047,7 +1047,7 @@ func (this *HTTPRequest) requestRemoteAddr(supportVar bool) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// X-Forwarded-For
|
// X-Forwarded-For
|
||||||
forwardedFor := this.RawReq.Header.Get("X-Forwarded-For")
|
var forwardedFor = this.RawReq.Header.Get("X-Forwarded-For")
|
||||||
if len(forwardedFor) > 0 {
|
if len(forwardedFor) > 0 {
|
||||||
commaIndex := strings.Index(forwardedFor, ",")
|
commaIndex := strings.Index(forwardedFor, ",")
|
||||||
if commaIndex > 0 {
|
if commaIndex > 0 {
|
||||||
@@ -1460,10 +1460,15 @@ func (this *HTTPRequest) setForwardHeaders(header http.Header) {
|
|||||||
if hasForwardHeader {
|
if hasForwardHeader {
|
||||||
header["X-Forwarded-For"] = []string{strings.Join(forwardedFor, ", ") + ", " + remoteAddr}
|
header["X-Forwarded-For"] = []string{strings.Join(forwardedFor, ", ") + ", " + remoteAddr}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
var clientRemoteAddr = this.requestRemoteAddr(true)
|
||||||
|
if len(clientRemoteAddr) > 0 && clientRemoteAddr != remoteAddr {
|
||||||
|
header["X-Forwarded-For"] = []string{clientRemoteAddr + ", " + remoteAddr}
|
||||||
} else {
|
} else {
|
||||||
header["X-Forwarded-For"] = []string{remoteAddr}
|
header["X-Forwarded-For"] = []string{remoteAddr}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Forwarded
|
// Forwarded
|
||||||
/**{
|
/**{
|
||||||
|
|||||||
Reference in New Issue
Block a user