gund / ng-http-interceptor

Http Interceptor library for Angular
MIT License
104 stars 16 forks source link

Interceptor not seeing all headers #157

Closed pford68 closed 7 years ago

pford68 commented 7 years ago

Hi, I am struggling with an issue in which not all response headers are visible to the response handler. We have a large set of response headers that are not seeing at all:

this.httpInterceptor.response().addInterceptor((res, method) => {
        return res.do(r => {
          console.log('response interceptor:', r.headers);
          let userInfoHeader = r.headers.get(this.appConfig.RESPONSE_USER_HEADER_NAME);
          let sessionToken = r.headers.get(this.appConfig.RESPONSE_USER_HEADER_NAME);

In the snippet above, r.headers only contains two of the headers, while all of the headers show up in the network console (Chrome). The ones that are not visible are CORS headers and some custom x-headers. Any help would be greatly appreciated.

gund commented 7 years ago

Hi, the library does only proxying over angular's http service so this is all that you have from the original response. According to this issue you won't get those headers anyways via vanilla XHR API.

In short you have to specify exactly names of the headers you want have access to via access-control-expose-headers: 'name-of-expose-header'

pford68 commented 7 years ago

That's for the quick response. Turns out the answer was none of the above--something simple and obvious (in retrospect) and that had nothing to do with anything you or I or the commenters in the linked article thought of.

gund commented 7 years ago

Hmm, interesting... So what was that anyway? 😀

pford68 commented 7 years ago

We needed to hit a certain proxy, in short, in order to see the headers, and we configured the wrong hostname in order to receive those headers. The HTML page itself returned those headers, but no AJAX calls went through the proxy, so we received no headers. Obvious now, but in the heat of the moment, no.

gund commented 7 years ago

Alright, I see now. Glad you solved it.