Skip to content

Commit

Permalink
check bin metadata first, require -bin be binary (technically breakin…
Browse files Browse the repository at this point in the history
…g change)
  • Loading branch information
sapphire-janrain committed Aug 21, 2023
1 parent c7c7ae6 commit 85c852c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions js/modules/k6/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,19 +459,17 @@ func (c *Client) parseInvokeParams(paramsVal goja.Value) (*invokeParams, error)
}
for hk, kv := range rawHeaders {
// TODO(rogchap): Should we manage a string slice?
strval, ok := kv.(string)
if !ok {
// The spec defines that Binary-valued keys end in -bin
// https://grpc.io/docs/what-is-grpc/core-concepts/#metadata
if strings.HasSuffix(hk, "-bin") {
binval, ok := kv.([]byte)
if !ok {
return result, fmt.Errorf("metadata %q value must be a string or binary", hk)
}
strval = string(binval)
} else {
return result, fmt.Errorf("metadata %q value must be a string", hk)
// The spec defines that Binary-valued keys end in -bin
// https://grpc.io/docs/what-is-grpc/core-concepts/#metadata
var strval string
if strings.HasSuffix(hk, "-bin") {
binval, ok := kv.([]byte)
if !ok {
return result, fmt.Errorf("metadata %q value must be binary", hk)
}
strval = string(binval)
} else if strval, ok = kv.(string); !ok {
return result, fmt.Errorf("metadata %q value must be a string", hk)
}
result.Metadata[hk] = strval
}
Expand Down

0 comments on commit 85c852c

Please sign in to comment.