diff --git a/client/client.go b/client/client.go index 3e158d1eabee4..4f1b03332bb86 100644 --- a/client/client.go +++ b/client/client.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "crypto/x509" - "fmt" "net" "net/url" "os" @@ -117,18 +116,14 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error if dialFn != nil { gopts = append(gopts, grpc.WithContextDialer(dialFn)) } - addressParts := strings.SplitN(address, "://", 2) - if len(addressParts) != 2 { - return nil, fmt.Errorf("%s is missing scheme", address) - } - if addressParts[0] == "tcp" { - // remove tcp scheme from address, since default dialer doesn't expect that - address = addressParts[1] - } } if address == "" { address = appdefaults.Address } + uri, err := url.Parse(address) + if err != nil { + return nil, err + } // Setting :authority pseudo header // - HTTP/2 (RFC7540) defines :authority pseudo header includes @@ -143,12 +138,13 @@ func New(ctx context.Context, address string, opts ...ClientOpt) (*Client, error } if authority == "" { // authority as hostname from target address - uri, err := url.Parse(address) - if err != nil { - return nil, err - } authority = uri.Host } + if uri.Scheme == "tcp" { + // remove tcp scheme from address, since default dialer doesn't expect that + address = uri.Host + } + gopts = append(gopts, grpc.WithAuthority(authority)) unary = append(unary, grpcerrors.UnaryClientInterceptor)