From 99a3346b94740f79e5c33fbd1ce8c00358ecd137 Mon Sep 17 00:00:00 2001 From: Frederik Date: Fri, 2 Mar 2018 18:01:37 +0100 Subject: [PATCH] Allow reflection calls to carry headers (#15) --- cmd/grpcurl/grpcurl.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index 57b714d..399dcea 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -73,9 +73,11 @@ var ( ) func init() { + // TODO: Allow separate headers for relflection/invocation flag.Var(&addlHeaders, "H", `Additional request headers in 'name: value' format. May specify more - than one via multiple -H flags.`) + than one via multiple -H flags. These headers will also be included in + reflection requests to a server.`) flag.Var(&protoset, "protoset", `The name of a file containing an encoded FileDescriptorSet. This file's contents will be used to determine the RPC schema instead of querying @@ -155,9 +157,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 +231,10 @@ func main() { fail(err, "Failed to process proto descriptor sets") } } else { + 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) }