From 22535d86439952a9764d65119bcc739929492717 Mon Sep 17 00:00:00 2001 From: RPRX <63339210+RPRX@users.noreply.github.com> Date: Sun, 21 Jul 2024 08:55:03 +0000 Subject: [PATCH] Fix SplitHTTP H3 didn't always reuse QUIC connection https://github.com/XTLS/Xray-core/issues/3560#issuecomment-2241531502 --- transport/internet/splithttp/dialer.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/transport/internet/splithttp/dialer.go b/transport/internet/splithttp/dialer.go index 3df653818efa..99558975aef5 100644 --- a/transport/internet/splithttp/dialer.go +++ b/transport/internet/splithttp/dialer.go @@ -41,6 +41,10 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in return &BrowserDialerClient{} } + tlsConfig := tls.ConfigFromStreamSettings(streamSettings) + isH2 := tlsConfig != nil && !(len(tlsConfig.NextProtocol) == 1 && tlsConfig.NextProtocol[0] == "http/1.1") + isH3 := tlsConfig != nil && (len(tlsConfig.NextProtocol) == 1 && tlsConfig.NextProtocol[0] == "h3") + globalDialerAccess.Lock() defer globalDialerAccess.Unlock() @@ -48,14 +52,13 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in globalDialerMap = make(map[dialerConf]DialerClient) } + if isH3 { + dest.Network = net.Network_UDP + } if client, found := globalDialerMap[dialerConf{dest, streamSettings}]; found { return client } - tlsConfig := tls.ConfigFromStreamSettings(streamSettings) - isH2 := tlsConfig != nil && !(len(tlsConfig.NextProtocol) == 1 && tlsConfig.NextProtocol[0] == "http/1.1") - isH3 := tlsConfig != nil && (len(tlsConfig.NextProtocol) == 1 && tlsConfig.NextProtocol[0] == "h3") - var gotlsConfig *gotls.Config if tlsConfig != nil { @@ -86,7 +89,6 @@ func getHTTPClient(ctx context.Context, dest net.Destination, streamSettings *in var uploadTransport http.RoundTripper if isH3 { - dest.Network = net.Network_UDP roundTripper := &http3.RoundTripper{ TLSClientConfig: gotlsConfig, Dial: func(ctx context.Context, addr string, tlsCfg *gotls.Config, cfg *quic.Config) (quic.EarlyConnection, error) {