panic
panic

Reputation: 2098

Handle HTTP response's headers

My API manages pagination via headers and I try to handle these in angular.

If I use chrome console I can find headers :

enter image description here

My responses handling method :

  /**
   * Get the body of an HTTP response.
   *
   * @param res
   * @returns {any|{}}
   */
  private static handleBody(res: Response) {
    console.log(res.headers);
    return res.json() || {};
  }

the result is :

enter image description here

How can I get my pagination headers in my angular app ?

Upvotes: 0

Views: 223

Answers (1)

Fenton
Fenton

Reputation: 250842

I suspect your browser is trying to protect you by not exposing custom headers.

You can permit headers by adding an additional response header:

Access-Control-Expose-Headers: X-Page, X-Per-Page, X-Total, X-Total-Pages

You should then be able to access these in the response.

WIthout this, you may only be able to access the simple headers:

  • Cache-Control
  • Content-Language
  • Content-Type
  • Expires
  • Last-Modified
  • Pragma

Upvotes: 1

Related Questions