From 149a93e0ec14b6fa2b80b6c47c9348186f343af4 Mon Sep 17 00:00:00 2001 From: Kristopher Wuollett Date: Tue, 30 Jan 2024 10:38:15 -0600 Subject: [PATCH] Use localhost for default unix domain socket authority (#445) --- cmd/grpcurl/grpcurl.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index c9802e1..aa83037 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -97,7 +97,8 @@ var ( value of the ":authority" pseudo-header in the HTTP/2 protocol. When TLS is used, this will also be used as the server name when verifying the server's certificate. It defaults to the address that is provided in the - positional arguments.`)) + positional arguments, or 'localhost' in the case of a unix domain + socket.`)) userAgent = flags.String("user-agent", "", prettify(` If set, the specified value will be added to the User-Agent header set by the grpc-go library. @@ -474,6 +475,13 @@ func main() { if *maxMsgSz > 0 { opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz))) } + network := "tcp" + if isUnixSocket != nil && isUnixSocket() { + network = "unix" + if *authority == "" { + *authority = "localhost" + } + } var creds credentials.TransportCredentials if *plaintext { if *authority != "" { @@ -538,10 +546,6 @@ func main() { } opts = append(opts, grpc.WithUserAgent(grpcurlUA)) - network := "tcp" - if isUnixSocket != nil && isUnixSocket() { - network = "unix" - } blockingDialTiming := dialTiming.Child("BlockingDial") defer blockingDialTiming.Done() cc, err := grpcurl.BlockingDial(ctx, network, target, creds, opts...)