From 0531be00499b1122bd2e1264fc1ea48b4e94c6dc Mon Sep 17 00:00:00 2001 From: Kai Davenport Date: Thu, 21 Jan 2021 11:46:59 +0000 Subject: [PATCH] feat(daml): add flag to control the max request size for a grpc request Signed-off-by: Kai Davenport --- cmd/grpcurl/grpcurl.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go index 60e0b38..38ed229 100644 --- a/cmd/grpcurl/grpcurl.go +++ b/cmd/grpcurl/grpcurl.go @@ -125,9 +125,15 @@ var ( The maximum total time the operation can take, in seconds. This is useful for preventing batch jobs that use grpcurl from hanging due to slow or bad network links or due to incorrect stream method usage.`)) - maxMsgSz = flags.Int("max-msg-sz", 0, prettify(` + maxReqSz = flags.Int("max-req-sz", 0, prettify(` + The maximum encoded size of a request message, in bytes, that grpcurl + will accept. If not specified, defaults to 4,194,304 (4 megabytes).`)) + maxResSz = flags.Int("max-res-sz", 0, prettify(` The maximum encoded size of a response message, in bytes, that grpcurl will accept. If not specified, defaults to 4,194,304 (4 megabytes).`)) + maxMsgSz = flags.Int("max-msg-sz", 0, prettify(` + The maximum encoded size of a request and response message, in bytes, that grpcurl + will accept. If not specified, defaults to 4,194,304 (4 megabytes).`)) emitDefaults = flags.Bool("emit-defaults", false, prettify(` Emit default values for JSON-encoded responses.`)) protosetOut = flags.String("protoset-out", "", prettify(` @@ -277,6 +283,12 @@ func main() { if *maxTime < 0 { fail(nil, "The -max-time argument must not be negative.") } + if *maxReqSz < 0 { + fail(nil, "The -max-req-sz argument must not be negative.") + } + if *maxResSz < 0 { + fail(nil, "The -max-res-sz argument must not be negative.") + } if *maxMsgSz < 0 { fail(nil, "The -max-msg-sz argument must not be negative.") } @@ -299,6 +311,17 @@ func main() { warn("The -emit-defaults is only used when using json format.") } + // apply max-msg-sz -> both max-req-sz & max-res-sz + // on the condition they do not have their own values + if *maxMsgSz != 0 { + if *maxReqSz == 0 { + maxReqSz = maxMsgSz + } + if *maxResSz == 0 { + maxResSz = maxMsgSz + } + } + args := flags.Args() if len(args) == 0 { @@ -400,8 +423,11 @@ func main() { Timeout: timeout, })) } - if *maxMsgSz > 0 { - opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxMsgSz))) + if *maxReqSz > 0 { + opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(*maxReqSz))) + } + if *maxResSz > 0 { + opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(*maxResSz))) } var creds credentials.TransportCredentials if !*plaintext {