Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient Subscribed Response Headers Undefined

can anyone give me any reasons on why I'm not getting any headers when getting a response back from http.post?

this.http.post<Response>(url, body).subscribe((res: Response) => console.log(res.headers));

res.headers logs 'undefined', however in Chrome DevTools, the response is showing the headers I'm looking for.

Side note: I do have Access-Control-Expose-Headers set to the header I'm wanting to expose.

Any idea why this would be?

like image 1000
Josh Avatar asked Dec 23 '22 08:12

Josh


1 Answers

To observe a response instead of a typecasted body, which the newer HttpClient does by default:

this.http.post(url, data, {observe: 'response'}).subscribe((res:Response) => {});

Ie. what you were doing was just type casting the data your server sent as <Response>.

like image 123
funkizer Avatar answered Dec 25 '22 21:12

funkizer