From d3fa362550d6bbfd4d95f2718a0383ef318f29b8 Mon Sep 17 00:00:00 2001 From: Ali Osman Atac Date: Tue, 14 Nov 2023 15:42:53 +0100 Subject: [PATCH] Adding support for overriding grpc authority pseudo header --- js/modules/k6/grpc/client.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/js/modules/k6/grpc/client.go b/js/modules/k6/grpc/client.go index 5c350e6de09..a0b4d20db93 100644 --- a/js/modules/k6/grpc/client.go +++ b/js/modules/k6/grpc/client.go @@ -236,6 +236,10 @@ func (c *Client) Connect(addr string, params goja.Value) (bool, error) { } opts = append(opts, grpc.WithTransportCredentials(tcred)) + if len(p.Authority) > 0 { + opts = append(opts, grpc.WithAuthority(p.Authority)) + } + if ua := state.Options.UserAgent; ua.Valid { opts = append(opts, grpc.WithUserAgent(ua.ValueOrZero())) } @@ -518,6 +522,7 @@ type connectParams struct { MaxReceiveSize int64 MaxSendSize int64 TLS map[string]interface{} + Authority string } func newConnectParams(rt *goja.Runtime, input goja.Value) (connectParams, error) { //nolint:funlen,gocognit,cyclop @@ -528,6 +533,7 @@ func newConnectParams(rt *goja.Runtime, input goja.Value) (connectParams, error) Timeout: time.Minute, MaxReceiveSize: 0, MaxSendSize: 0, + Authority: "", } if common.IsNullish(input) { @@ -619,6 +625,12 @@ func newConnectParams(rt *goja.Runtime, input goja.Value) (connectParams, error) " it needs to be a string or an array of PEM formatted strings", v) } } + case "authority": + var ok bool + params.Authority, ok = v.(string) + if !ok { + return params, fmt.Errorf("invalid authority value: '%#v', it needs to be a string", v) + } default: return params, fmt.Errorf("unknown connect param: %q", k) }