Skip to content

Commit

Permalink
Adding support for overriding grpc authority pseudo header
Browse files Browse the repository at this point in the history
  • Loading branch information
ali-atac committed Nov 14, 2023
1 parent 24ae4d9 commit d3fa362
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions js/modules/k6/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit d3fa362

Please sign in to comment.