Parse X-Forwarded-For in http transport (#142)

* Parse X-Forwarded-For

* Update hub.go

Co-authored-by: RPRX <63339210+rprx@users.noreply.github.com>
pull/2714/head
lucifer 4 years ago committed by GitHub
parent 8c82fd3e6d
commit 4c9210cf11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -9,16 +9,17 @@ import (
"strings"
"time"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
"v2ray.com/core/common"
"v2ray.com/core/common/net"
http_proto "v2ray.com/core/common/protocol/http"
"v2ray.com/core/common/serial"
"v2ray.com/core/common/session"
"v2ray.com/core/common/signal/done"
"v2ray.com/core/transport/internet"
"v2ray.com/core/transport/internet/tls"
"golang.org/x/net/http2"
"golang.org/x/net/http2/h2c"
)
type Listener struct {
@ -82,6 +83,11 @@ func (l *Listener) ServeHTTP(writer http.ResponseWriter, request *http.Request)
}
}
forwardedAddrs := http_proto.ParseXForwardedFor(request.Header)
if len(forwardedAddrs) > 0 && forwardedAddrs[0].Family().IsIP() {
remoteAddr.(*net.TCPAddr).IP = forwardedAddrs[0].IP()
}
done := done.New()
conn := net.NewConnection(
net.ConnectionOutput(request.Body),

Loading…
Cancel
Save