github.com/sagernet/sing@v0.2.6/protocol/http/addr.go (about) 1 package http 2 3 import ( 4 "net/http" 5 "strings" 6 7 M "github.com/sagernet/sing/common/metadata" 8 ) 9 10 func SourceAddress(request *http.Request) M.Socksaddr { 11 address := M.ParseSocksaddr(request.RemoteAddr) 12 forwardFrom := request.Header.Get("X-Forwarded-For") 13 if forwardFrom != "" { 14 for _, from := range strings.Split(forwardFrom, ",") { 15 originAddr := M.ParseAddr(from) 16 if originAddr.IsValid() { 17 address.Addr = originAddr 18 } 19 } 20 } 21 return address.Unwrap() 22 }