You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The server of this gRPC sets the metadata header some-header in Golang:
func (smyServer) RespondMetadata(ctx context.Context, request*emptypb.Empty) (*emptypb.Empty, error) {
// ... Do some other stuff// All side-effects resulting from this call happen sucessfully in the server. e.g. printing to console// Set the metadata key value pair as headerheader:=metadata.New(map[string]string{"some-header": "some-value"})
err:=grpc.SetHeader(ctx, header)
iferr!=nil {
returnnil, fmt.Errorf("Failed to set header: %w", err)
}
return&emptypb.Empty{}, nil
}
I know this is working fine because I can create a Golang client for this server and successfully read the headers, both by dialing into the grpc port directly, or by dialing an Envoy proxy that I have already set up.
Metadata transformed into HTTP headers
If I create my grpc client for the browser using grpc-web, I can see the metadata present in the HTTP Response Headers of the browser Network tab:
Issue within browser (grpc-web) typescript code
However, in the code the metadata is always empty.
And I have tried calling the method and reading metadata in the following ways:
constgrpcRequest=newgoogle_protobuf_empty_pb.Empty();constcall=client.respondMetadata(grpcRequest,{},(err,response)=>{if(err){console.log("There was an error",err);}else{// response is of type google.protobuf.Empty// So I can't read metadata from hereconsole.log("Successfull response: ",response)}});call.on('status',(status)=>{console.log("Status metadata: ",status.metadata)// This is empty: {}console.log("Status!:",status)});call.on('metadata',(metadata)=>{console.log("Received metadata: ",metadata);// This is empty: {}constvalue=metadata['some-header'];console.log('The received header is: ',value);// this is undefined})
Any ideas how can I read response metadata? Or why are these approaches not working?
The text was updated successfully, but these errors were encountered:
I'm not really familiar with the go grpc server, and how metadata is propagated, but we do have a demo with a Node server which echos the metadata and prints it out.
You can run it using:
docker-compose up --build node-server envoy ts-client
And you can see the metadata being printed out in the console, with the following code:
In short, the metadata of my web-grpc client is always empty.
Proto definition
Let's say my proto file looks like:
Code generation
I generated code for my proto files using
"grpc-web": "^1.4.2"
.And protoc:
The command is:
Server-side
The server of this gRPC sets the metadata header
some-header
in Golang:I know this is working fine because I can create a Golang client for this server and successfully read the headers, both by dialing into the grpc port directly, or by dialing an Envoy proxy that I have already set up.
Metadata transformed into HTTP headers
If I create my grpc client for the browser using grpc-web, I can see the metadata present in the HTTP Response Headers of the browser Network tab:
Issue within browser (grpc-web) typescript code
However, in the code the metadata is always empty.
I initialize my client in the following way:
And I have tried calling the method and reading metadata in the following ways:
Any ideas how can I read response metadata? Or why are these approaches not working?
The text was updated successfully, but these errors were encountered: