Add gRPC Transport support (#356)

Co-authored-by: JimhHan <50871214+JimhHan@users.noreply.github.com>
This commit is contained in:
RPRX 2021-03-14 15:02:07 +00:00 committed by GitHub
parent 60b06877bf
commit a0a32ee00d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 1564 additions and 4 deletions

View file

@ -18,8 +18,13 @@ import (
"golang.org/x/net/http2"
)
type dialerConf struct {
net.Destination
*internet.SocketConfig
}
var (
globalDialerMap map[net.Destination]*http.Client
globalDialerMap map[dialerConf]*http.Client
globalDialerAccess sync.Mutex
)
@ -28,10 +33,10 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C
defer globalDialerAccess.Unlock()
if globalDialerMap == nil {
globalDialerMap = make(map[net.Destination]*http.Client)
globalDialerMap = make(map[dialerConf]*http.Client)
}
if client, found := globalDialerMap[dest]; found {
if client, found := globalDialerMap[dialerConf{dest, sockopt}]; found {
return client, nil
}
@ -87,7 +92,7 @@ func getHTTPClient(ctx context.Context, dest net.Destination, tlsSettings *tls.C
Transport: transport,
}
globalDialerMap[dest] = client
globalDialerMap[dialerConf{dest, sockopt}] = client
return client, nil
}