How to get header value from Streaming.
Hello!
I do have a simple endpoint that streams objects from the database. In headers, I'm sending extra header with information about the total amount of items. The header is called total_count
I'm seeing the value in the response header in the network debugger. However, I'm unable to get it using your framework.
const headers = new grpc.Metadata();
headers.set('authorization', login?.accessToken || '');
const response = client.listDemoObjects(req, headers);
const items: DemoObject.AsObject[] = [];
let totalItems: number;
response.on('status', (status) => {
console.log(status.code);
console.log(status.details);
console.log(status.metadata); // total_count is not here
});
response.on('end', (status) => {
console.log(status); // total_count is not here
});
response.on('data', (data) => {
items.push(data.toObject()); // total_count is not here
});
How can I get response headers?
To be 100% clear I'm not using trailers. :-)
As noted here you should be able to read the response headers in the "metadata" event. The GrpcWebClientReadableStream implementation directly reads the response headers from the xhr event and will emit the corresponding event.
Hi @lukasmoellerch why do you think the "metadata" doesn't show the other values that were set on the trailers?
This is from the response headers

While this is from the console when I tried to log the "metadata"

And this is my code
stream.on('metadata', (metadata) => { console.log('metadata', metadata); });
I'd assume that status and message have special handling. Does it not appear anywhere in the response? Maybe in the status event?
Already tried to log the status @lukasmoellerch but the metadata there doesn't contain anything.
This is what the status contains, there should be more values than what's in this picture but for some reason it only shows the values below.

How about the error event? I am only on mobile right now, can investigate more this evening.
Same goes for the error event, only shows code, details, and an empty metadata.
Could it be because I'm using it on ReactJS + Typescript? Since from our back-end dev's side it does show all values and he's just using plain javascript.

Hello!
You have to add an additional header in the envoy server so that grpc lib will be able to use it. In my case it was.
expose_headers: grpc-status,grpc-message,total_items
I'm closing this issue as not an issue.