headers.go 388 B

123456789101112131415161718192021
  1. package http
  2. import (
  3. "net/http"
  4. "strings"
  5. "v2ray.com/core/common/net"
  6. )
  7. func ParseXForwardedFor(header http.Header) []net.Address {
  8. xff := header.Get("X-Forwarded-For")
  9. if len(xff) == 0 {
  10. return nil
  11. }
  12. list := strings.Split(xff, ",")
  13. addrs := make([]net.Address, 0, len(list))
  14. for _, proxy := range list {
  15. addrs = append(addrs, net.ParseAddress(proxy))
  16. }
  17. return addrs
  18. }