From db940a7d51bfccac429ef4dd2abf9a71dc9f7034 Mon Sep 17 00:00:00 2001 From: Frederik Galle Date: Tue, 27 Feb 2018 20:45:36 +0100 Subject: [PATCH] Allow reflection calls to carry headers --- cmd/grpcurl/grpcurl.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index 57b714d..8ea63dc 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -54,6 +54,9 @@ var ( read from stdin. For calls that accept a stream of requests, the contents should include all such request messages concatenated together (optionally separated by whitespace).`) + reflectWithHeaders = flag.Bool("reflect-with-headers", false, + `Include headers provided with -H when performing reflection calls + against a remote server.`) connectTimeout = flag.String("connect-timeout", "", `The maximum time, in seconds, to wait for connection to be established. Defaults to 10 seconds.`) @@ -155,9 +158,6 @@ func main() { if *data != "" { fail(nil, "The -d argument is not used with 'list' or 'describe' verb.") } - if len(addlHeaders) > 0 { - fail(nil, "The -H argument is not used with 'list' or 'describe' verb.") - } if len(args) > 0 { symbol = args[0] args = args[1:] @@ -232,8 +232,13 @@ func main() { fail(err, "Failed to process proto descriptor sets") } } else { + refCtx := ctx + if *reflectWithHeaders { + md := grpcurl.MetadataFromHeaders(addlHeaders) + refCtx = metadata.NewOutgoingContext(ctx, md) + } cc = dial() - refClient = grpcreflect.NewClient(ctx, reflectpb.NewServerReflectionClient(cc)) + refClient = grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(cc)) descSource = grpcurl.DescriptorSourceFromServer(ctx, refClient) }