@@ -110,14 +110,14 @@ func (c tlsCreds) Info() ProtocolInfo {
110110func (c * tlsCreds ) ClientHandshake (ctx context.Context , authority string , rawConn net.Conn ) (_ net.Conn , _ AuthInfo , err error ) {
111111 // use local cfg to avoid clobbering ServerName if using multiple endpoints
112112 cfg := credinternal .CloneTLSConfig (c .config )
113- if cfg .ServerName == "" {
114- serverName , _ , err := net .SplitHostPort (authority )
115- if err != nil {
116- // If the authority had no host port or if the authority cannot be parsed, use it as-is.
117- serverName = authority
118- }
119- cfg .ServerName = serverName
113+
114+ serverName , _ , err := net .SplitHostPort (authority )
115+ if err != nil {
116+ // If the authority had no host port or if the authority cannot be parsed, use it as-is.
117+ serverName = authority
120118 }
119+ cfg .ServerName = serverName
120+
121121 conn := tls .Client (rawConn , cfg )
122122 errChannel := make (chan error , 1 )
123123 go func () {
@@ -259,9 +259,11 @@ func applyDefaults(c *tls.Config) *tls.Config {
259259// certificates to establish the identity of the client need to be included in
260260// the credentials (eg: for mTLS), use NewTLS instead, where a complete
261261// tls.Config can be specified.
262- // serverNameOverride is for testing only. If set to a non empty string,
263- // it will override the virtual host name of authority (e.g. :authority header
264- // field) in requests.
262+ //
263+ // serverNameOverride is for testing only. If set to a non empty string, it will
264+ // override the virtual host name of authority (e.g. :authority header field) in
265+ // requests. Users should use grpc.WithAuthority passed to grpc.NewClient to
266+ // override the authority of the client instead.
265267func NewClientTLSFromCert (cp * x509.CertPool , serverNameOverride string ) TransportCredentials {
266268 return NewTLS (& tls.Config {ServerName : serverNameOverride , RootCAs : cp })
267269}
@@ -271,9 +273,11 @@ func NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string) Transpor
271273// certificates to establish the identity of the client need to be included in
272274// the credentials (eg: for mTLS), use NewTLS instead, where a complete
273275// tls.Config can be specified.
274- // serverNameOverride is for testing only. If set to a non empty string,
275- // it will override the virtual host name of authority (e.g. :authority header
276- // field) in requests.
276+ //
277+ // serverNameOverride is for testing only. If set to a non empty string, it will
278+ // override the virtual host name of authority (e.g. :authority header field) in
279+ // requests. Users should use grpc.WithAuthority passed to grpc.NewClient to
280+ // override the authority of the client instead.
277281func NewClientTLSFromFile (certFile , serverNameOverride string ) (TransportCredentials , error ) {
278282 b , err := os .ReadFile (certFile )
279283 if err != nil {
0 commit comments