What is the Access-Control-Expose-Headers header?
The Access-Control-Expose-Headers response header names which response headers JavaScript is permitted to read on a cross-origin request. Without it, scripts can only access a small CORS-safelisted set such as Content-Type, Cache-Control, and Content-Language.
API Usage & Best Practices
- Expose custom headers: List anything your client needs to read, such as
X-Total-Countfor pagination or a customX-Request-Idfor tracing. - Sent on the actual response: Unlike most CORS headers, this one belongs on the actual
200response, not the preflight. The wildcard*exposes all headers but is ignored for credentialed requests.
Examples
HTTP/1.1 200 OKAccess-Control-Allow-Origin: https://app.example.comAccess-Control-Expose-Headers: X-Total-Count, X-Request-Id