Skip to content

Commit 149a93e

Browse files
authored
Use localhost for default unix domain socket authority (#445)
1 parent 252b57f commit 149a93e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

cmd/grpcurl/grpcurl.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ var (
9797
value of the ":authority" pseudo-header in the HTTP/2 protocol. When TLS
9898
is used, this will also be used as the server name when verifying the
9999
server's certificate. It defaults to the address that is provided in the
100-
positional arguments.`))
100+
positional arguments, or 'localhost' in the case of a unix domain
101+
socket.`))
101102
userAgent = flags.String("user-agent", "", prettify(`
102103
If set, the specified value will be added to the User-Agent header set
103104
by the grpc-go library.
@@ -474,6 +475,13 @@ func main() {
474475
if *maxMsgSz > 0 {
475476
opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz)))
476477
}
478+
network := "tcp"
479+
if isUnixSocket != nil && isUnixSocket() {
480+
network = "unix"
481+
if *authority == "" {
482+
*authority = "localhost"
483+
}
484+
}
477485
var creds credentials.TransportCredentials
478486
if *plaintext {
479487
if *authority != "" {
@@ -538,10 +546,6 @@ func main() {
538546
}
539547
opts = append(opts, grpc.WithUserAgent(grpcurlUA))
540548

541-
network := "tcp"
542-
if isUnixSocket != nil && isUnixSocket() {
543-
network = "unix"
544-
}
545549
blockingDialTiming := dialTiming.Child("BlockingDial")
546550
defer blockingDialTiming.Done()
547551
cc, err := grpcurl.BlockingDial(ctx, network, target, creds, opts...)

0 commit comments

Comments
 (0)