Open alexdohm opened 2 years ago
Thanks for the question!
I'm curious if in your testing, are you able to get the 'metadata' event callback without using the interceptor?
I'm not exactly sure how to generate a 'metadata' message on the server. But i've tested with a 'status' interceptor with metadata, and it seems to work for me.
So here, similar to the code below: https://github.com/grpc/grpc-web/blob/8c5502186445e35002697f4bd8d1b820abdbed5d/net/grpc/gateway/examples/echo/commonjs-example/client.js#L41-L47
I've added a new block to intercept the 'status' callback, where it prints out and replaces the metadata.
} else if (eventType == 'status') {
const newCallback = (status) => {
console.log(['Old metadata: ', status.metadata]);
callback({metadata: {'new_metadata': 'value'}});
};
this.stream.on('status', newCallback);
}
.. and that seems to work..
And so far i'm not able to tell any reason why 'metadata' callback would behave differently than 'data' or 'status'..
I've looked through the existing tickets and am still lost on how to access the response headers in a streamInterceptor. I need to update a JWT token if an Authorization header is set in a stream response.
My code uses both unary and streaming calls, and unary calls are working successfully with promise based interceptor and promise-base client with reading and setting headers in both request and response. Based on #988 stream interceptors are only meant for a normal callback-based client and interceptor. Using #766 I implemented a stream interceptor and in my golang server side code, I tried setting the metadata header as a test and sending the stream :
By inspecting the http response, I see that the header is set, however the 'metadata' event is never intercepted and 'data' returns my proto response, but I have no access to the header / metadata.
I've noticed that I have access to a promise based client in my autogenerated files for the stream, but I'm not sure how that would be integrated with a stream interceptor, or if I need to use a unary interceptor with the stream in some way.
options are defined as such
and I link my streaming call as such:
I'm using grpc-web v.1.2.1