mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-05-01 01:44:15 +00:00
Fix(httpupgrade): X-Forwarded-For
header not read. (#3172)
This commit is contained in:
parent
70a5fe9a25
commit
2cafb3ef89
2 changed files with 34 additions and 0 deletions
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
http_proto "github.com/xtls/xray-core/common/protocol/http"
|
||||
"github.com/xtls/xray-core/common/session"
|
||||
"github.com/xtls/xray-core/transport/internet"
|
||||
"github.com/xtls/xray-core/transport/internet/stat"
|
||||
|
@ -68,6 +69,20 @@ func (s *server) Handle(conn net.Conn) (stat.Connection, error) {
|
|||
_ = conn.Close()
|
||||
return nil, err
|
||||
}
|
||||
|
||||
forwardedAddrs := http_proto.ParseXForwardedFor(req.Header)
|
||||
remoteAddr := conn.RemoteAddr()
|
||||
if len(forwardedAddrs) > 0 && forwardedAddrs[0].Family().IsIP() {
|
||||
remoteAddr = &net.TCPAddr{
|
||||
IP: forwardedAddrs[0].IP(),
|
||||
Port: int(0),
|
||||
}
|
||||
}
|
||||
if remoteAddr == nil {
|
||||
return nil, newError("remoteAddr is nil")
|
||||
}
|
||||
|
||||
conn = newConnection(conn, remoteAddr)
|
||||
return stat.Connection(conn), nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue