2

I am trying to access a new header I have added to my API response in TypeScript. In the Network tab of my developer tools, I can see that the new header I added is present, but when I try req.headers.get("x-web-frontend-version") I just get null.

Here is my code and image of my network tab:

intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    let headers = req.headers;

    console.log('HEADERS: ' + headers.get('x-web-frontend-version'));

    const authReq = req.clone({
      headers: headers
    });

    return next.handle(authReq);
  }
}

Image:

enter image description here

2
  • Could it be that req.headers are the headers of the request but x-web-frontend-version are headers of a response? Commented Aug 3, 2021 at 10:06
  • I do believe that it the case, do you know how I would go about getting the response? Commented Aug 3, 2021 at 10:06

1 Answer 1

2

Assuming that the function Intercept is in some service file, such as some.service.ts, in the component file, some.component.ts, I would try the following:

const xWebFrontednVersion: string;
this.someService.intercept(req, next).toPromise().then(response => {
        this.xWebFrontednVersion = response.headers.get('x-web-frontend-version');
})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.