Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with getting response metadata from the Unary Interceptors API #909

Closed
ghost opened this issue Jul 20, 2020 · 3 comments · Fixed by #910
Closed

Problem with getting response metadata from the Unary Interceptors API #909

ghost opened this issue Jul 20, 2020 · 3 comments · Fixed by #910

Comments

@ghost
Copy link

ghost commented Jul 20, 2020

I try to implement the Promise-based client with my gRPC-web and I have a problem with getting metadata from Unary Interceptors API. In the gRPC blog: https://grpc.io/blog/grpc-web-interceptor/ they recommend using the response.getMetadata() in the Unary Interceptors invoker callback. So after the implementation, my response metadata is returned only a x-envoy-upstream-service-time

1595241469393@2x

However, if I use the gRPC-web callback-based API. It must return my custom value in status metadata. Thank you for the advice!

1595242658130

@stanley-cheung
Copy link
Collaborator

stanley-cheung commented Jul 21, 2020

There are 2 concepts here: initial metadata vs trailing metadata. In your callback-based example above, you are accessing the trailing metadata via the .on('status', ... callback. status.metadata in that callback is the trailing metadata.

In your promise-based interceptor, response.getMetadata() gets you the initial metadata. In order to access the trailing metadata in your promise-based interceptor, you need response.getStatus().metadata.

Similarly, in your callback-based client, .on('metadata', ...) will get you the initial metadata.

See this unit test on how to access both the initial and trailing metadata in your promise-based UnaryInterceptor.

@ghost
Copy link
Author

ghost commented Jul 21, 2020

@stanley-cheung, I use the JavaScript implementation compare with the UnaryInterceptor TypeScript example.

Screen Shot 2563-07-21 at 14 42 21

After that, I try to develop the UnaryInterceptor. However, the browser console alert the TypeError: response.getStatus is not a function at eval and TypeError: response.getResponseMessage is not a function at eval. So please advise me, did I do something wrong with my code or not? Thank you for your help.

Screen Shot 2563-07-21 at 14 40 29

Screen Shot 2563-07-21 at 14 40 41

@stanley-cheung
Copy link
Collaborator

Ah. I see. You probably run into this particular issue: #877 (comment), where some of the symbols/functions for the UnaryResponse class (in your code, the response object) has been optimized away by the closure compiler. This should be fixed in #886 in master. I will probably cut a new release 1.2.1. which will contain this fix soon.

borissmidt pushed a commit to borissmidt/grpc-web that referenced this issue Feb 16, 2022
* Fix CI exit code reporting
* Simplify local integration test usage
* Fixed webpack compatibility with old browsers (safari 9)
* Upgrade karma
* Disabled websocket tests for old versions of firefox
* Removed firefox 21 due to SSL incompatibility
* Updated latest browser versions
* Revert "added websocket transport to cancel propagation test (grpc#904)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant