mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-10 03:17:11 -05:00
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>
This commit is contained in:
parent
8c82fd3e6d
commit
4c9210cf11
@ -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…
Reference in New Issue
Block a user