Skip to content

Commit

Permalink
Fix XTLS/Xray-core#289 (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
Autumn216 committed Mar 1, 2021
1 parent 244820f commit 09f88e6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions transport/internet/http/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/xtls/xray-core/common/buf"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/common/net/cnc"
"github.com/xtls/xray-core/common/session"
"github.com/xtls/xray-core/transport/internet"
"github.com/xtls/xray-core/transport/internet/tls"
"github.com/xtls/xray-core/transport/pipe"
Expand All @@ -22,7 +23,7 @@ var (
globalDialerAccess sync.Mutex
)

func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config) (*http.Client, error) {
func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.Config, sockopt *internet.SocketConfig) (*http.Client, error) {
globalDialerAccess.Lock()
defer globalDialerAccess.Unlock()

Expand All @@ -49,17 +50,24 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C
}
address := net.ParseAddress(rawHost)

pconn, err := internet.DialSystem(ctx, net.TCPDestination(address, port), nil)
dctx := context.Background()
dctx = session.ContextWithID(dctx, session.IDFromContext(ctx))
dctx = session.ContextWithOutbound(dctx, session.OutboundFromContext(ctx))

pconn, err := internet.DialSystem(dctx, net.TCPDestination(address, port), sockopt)
if err != nil {
newError("failed to dial to " + addr).Base(err).AtError().WriteToLog()
return nil, err
}

cn := gotls.Client(pconn, tlsConfig)
if err := cn.Handshake(); err != nil {
newError("failed to dial to " + addr).Base(err).AtError().WriteToLog()
return nil, err
}
if !tlsConfig.InsecureSkipVerify {
if err := cn.VerifyHostname(tlsConfig.ServerName); err != nil {
newError("failed to dial to " + addr).Base(err).AtError().WriteToLog()
return nil, err
}
}
Expand Down Expand Up @@ -90,7 +98,7 @@ func Dial(ctx context.Context, dest net.Destination, streamSettings *internet.Me
if tlsConfig == nil {
return nil, newError("TLS must be enabled for http transport.").AtWarning()
}
client, err := getHTTPClient(ctx, dest, tlsConfig)
client, err := getHTTPClient(ctx, dest, tlsConfig, streamSettings.SocketSettings)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 09f88e6

Please sign in to comment.