Skip to content

Commit

Permalink
Fix SplitHTTP H3 didn't always reuse QUIC connection
Browse files Browse the repository at this point in the history
  • Loading branch information
RPRX committed Jul 21, 2024
1 parent 529f206 commit 22535d8
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions transport/internet/splithttp/dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,24 @@ 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()

if globalDialerMap == nil {
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 {
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 22535d8

Please sign in to comment.