1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2026-01-06 01:05:35 -05:00

read original addr from x-forwarded-for header if present

This commit is contained in:
Darien Raymond
2017-12-18 20:34:00 +01:00
parent a0b2c285b2
commit 91ca88bcff
6 changed files with 93 additions and 13 deletions

View File

@@ -0,0 +1,21 @@
package http
import (
"net/http"
"strings"
"v2ray.com/core/common/net"
)
func ParseXForwardedFor(header http.Header) []net.Address {
xff := header.Get("X-Forwarded-For")
if len(xff) == 0 {
return nil
}
list := strings.Split(xff, ",")
addrs := make([]net.Address, 0, len(list))
for _, proxy := range list {
addrs = append(addrs, net.ParseAddress(proxy))
}
return addrs
}