@@ -110,14 +110,14 @@ func (c tlsCreds) Info() ProtocolInfo {
110
110
func (c * tlsCreds ) ClientHandshake (ctx context.Context , authority string , rawConn net.Conn ) (_ net.Conn , _ AuthInfo , err error ) {
111
111
// use local cfg to avoid clobbering ServerName if using multiple endpoints
112
112
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
120
118
}
119
+ cfg .ServerName = serverName
120
+
121
121
conn := tls .Client (rawConn , cfg )
122
122
errChannel := make (chan error , 1 )
123
123
go func () {
@@ -259,9 +259,11 @@ func applyDefaults(c *tls.Config) *tls.Config {
259
259
// certificates to establish the identity of the client need to be included in
260
260
// the credentials (eg: for mTLS), use NewTLS instead, where a complete
261
261
// 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.
265
267
func NewClientTLSFromCert (cp * x509.CertPool , serverNameOverride string ) TransportCredentials {
266
268
return NewTLS (& tls.Config {ServerName : serverNameOverride , RootCAs : cp })
267
269
}
@@ -271,9 +273,11 @@ func NewClientTLSFromCert(cp *x509.CertPool, serverNameOverride string) Transpor
271
273
// certificates to establish the identity of the client need to be included in
272
274
// the credentials (eg: for mTLS), use NewTLS instead, where a complete
273
275
// 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.
277
281
func NewClientTLSFromFile (certFile , serverNameOverride string ) (TransportCredentials , error ) {
278
282
b , err := os .ReadFile (certFile )
279
283
if err != nil {
0 commit comments