Allow reflection calls to carry headers (#15)

This commit is contained in:
Frederik 2018-03-02 18:01:37 +01:00 committed by Joshua Humphries
parent fd0131d472
commit 99a3346b94
1 changed files with 6 additions and 5 deletions

View File

@ -73,9 +73,11 @@ var (
) )
func init() { func init() {
// TODO: Allow separate headers for relflection/invocation
flag.Var(&addlHeaders, "H", flag.Var(&addlHeaders, "H",
`Additional request headers in 'name: value' format. May specify more `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", flag.Var(&protoset, "protoset",
`The name of a file containing an encoded FileDescriptorSet. This file's `The name of a file containing an encoded FileDescriptorSet. This file's
contents will be used to determine the RPC schema instead of querying contents will be used to determine the RPC schema instead of querying
@ -155,9 +157,6 @@ func main() {
if *data != "" { if *data != "" {
fail(nil, "The -d argument is not used with 'list' or 'describe' verb.") 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 { if len(args) > 0 {
symbol = args[0] symbol = args[0]
args = args[1:] args = args[1:]
@ -232,8 +231,10 @@ func main() {
fail(err, "Failed to process proto descriptor sets") fail(err, "Failed to process proto descriptor sets")
} }
} else { } else {
md := grpcurl.MetadataFromHeaders(addlHeaders)
refCtx := metadata.NewOutgoingContext(ctx, md)
cc = dial() cc = dial()
refClient = grpcreflect.NewClient(ctx, reflectpb.NewServerReflectionClient(cc)) refClient = grpcreflect.NewClient(refCtx, reflectpb.NewServerReflectionClient(cc))
descSource = grpcurl.DescriptorSourceFromServer(ctx, refClient) descSource = grpcurl.DescriptorSourceFromServer(ctx, refClient)
} }