Skip to content

Commit

Permalink
Merge fb373ca into 6556342
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphire-janrain authored Aug 23, 2023
2 parents 6556342 + fb373ca commit 26786b5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
13 changes: 11 additions & 2 deletions js/modules/k6/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,8 +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
var strval string
if strings.HasSuffix(hk, "-bin") {
var binval []byte
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
25 changes: 25 additions & 0 deletions js/modules/k6/grpc/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,31 @@ func TestClient(t *testing.T) {
}
`},
},
{
name: "RequestBinHeaders",
initString: codeBlock{
code: `
var client = new grpc.Client();
client.load([], "../../../../lib/testutils/httpmultibin/grpc_testing/test.proto");`,
},
setup: func(tb *httpmultibin.HTTPMultiBin) {
tb.GRPCStub.EmptyCallFunc = func(ctx context.Context, _ *grpc_testing.Empty) (*grpc_testing.Empty, error) {
md, ok := metadata.FromIncomingContext(ctx)
if !ok || len(md["x-load-tester-bin"]) == 0 || md["x-load-tester-bin"][0] != string([]byte{2, 200}) {
return nil, status.Error(codes.FailedPrecondition, "")
}

return &grpc_testing.Empty{}, nil
}
},
vuString: codeBlock{code: `
client.connect("GRPCBIN_ADDR");
var resp = client.invoke("grpc.testing.TestService/EmptyCall", {}, { metadata: { "X-Load-Tester-bin": new Uint8Array([2, 200]) } })
if (resp.status !== grpc.StatusOK) {
throw new Error("failed to send correct headers in the request")
}
`},
},
{
name: "ResponseMessage",
initString: codeBlock{
Expand Down

0 comments on commit 26786b5

Please sign in to comment.