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

[Question] How to access all http response headers with interceptor or other? #908

Closed
kybetter opened this issue Jul 20, 2020 · 1 comment · Fixed by #910
Closed

[Question] How to access all http response headers with interceptor or other? #908

kybetter opened this issue Jul 20, 2020 · 1 comment · Fixed by #910

Comments

@kybetter
Copy link

e.g:

import { FooPromiseClient } from './fooService_grpc_web_pb';

const myInterceptor = function () {}

myInterceptor.prototype.intercept = function (request, invoker) {
  return invoker(request).then((response) => {
    return response;
  });
}

const fooService = new FooPromiseClient('http://xxx.xxx', {}, {
   'unaryInterceptors': [new myInterceptor()]
});

fooService.foo(someRequest).then(response => {
  // I only got empty metadata here, how to access all http response headers? 
})
@stanley-cheung
Copy link
Collaborator

e.g:

import { FooPromiseClient } from './fooService_grpc_web_pb';

const myInterceptor = function () {}

myInterceptor.prototype.intercept = function (request, invoker) {
  return invoker(request).then((response) => {
    # you can access the initial metadata here: response.getMetadata()
    # you can access the trailing metadata here: response.getStatus().metadata
    return response;
  });
}

Basically, you have to access the metadata in the interceptor itself, not after it has already returned. See this unit test as an example.

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.

2 participants