mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-04 14:13:03 +00:00
Fix(httpupgrade): X-Forwarded-For
header not read. (#3172)
This commit is contained in:
parent
70a5fe9a25
commit
2cafb3ef89
19
transport/internet/httpupgrade/connection.go
Normal file
19
transport/internet/httpupgrade/connection.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package httpupgrade
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
type connnection struct {
|
||||||
|
net.Conn
|
||||||
|
remoteAddr net.Addr
|
||||||
|
}
|
||||||
|
|
||||||
|
func newConnection(conn net.Conn, remoteAddr net.Addr) *connnection {
|
||||||
|
return &connnection{
|
||||||
|
Conn: conn,
|
||||||
|
remoteAddr: remoteAddr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *connnection) RemoteAddr() net.Addr {
|
||||||
|
return c.remoteAddr
|
||||||
|
}
|
@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/net"
|
"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/common/session"
|
||||||
"github.com/xtls/xray-core/transport/internet"
|
"github.com/xtls/xray-core/transport/internet"
|
||||||
"github.com/xtls/xray-core/transport/internet/stat"
|
"github.com/xtls/xray-core/transport/internet/stat"
|
||||||
@ -68,6 +69,20 @@ func (s *server) Handle(conn net.Conn) (stat.Connection, error) {
|
|||||||
_ = conn.Close()
|
_ = conn.Close()
|
||||||
return nil, err
|
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
|
return stat.Connection(conn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user