Access-Control-Expose-Headers - HTTP 编辑
The Access-Control-Expose-Headers
response header indicates which headers can be exposed as part of the response by listing their names.
By default, only the 7 CORS-safelisted response headers are exposed:
If you want clients to be able to access other headers, you have to list them using the Access-Control-Expose-Headers
header. Content-Length
was not part of the original set safelisted response headers [ref].
Header type | Response header |
---|---|
Forbidden header name | no |
Syntax
Access-Control-Expose-Headers: <header-name>, <header-name>, ... Access-Control-Expose-Headers: *
Directives
- <header-name>
- A list of exposed headers consisting of zero or more header names other than the CORS-safelisted request headers that the resource might use and can be exposed.
*
(wildcard)- The value "
*
" only counts as a special wildcard value for requests without credentials (requests without HTTP cookies or HTTP authentication information). In requests with credentials, it is treated as the literal header name "*
" without special semantics.
Note that theAuthorization
header can't be wildcarded and always needs to be listed explicitly.
Examples
To expose a non-CORS-safelisted request header, you can specify:
Access-Control-Expose-Headers: Content-Length
To additionally expose a custom header, like X-Kuma-Revision
, you can specify multiple headers separated by a comma:
Access-Control-Expose-Headers: Content-Length, X-Kuma-Revision
In requests without credentials, you can also use a wildcard value:
Access-Control-Expose-Headers: *
However, this won't wildcard the Authorization
header, so if you need to expose that, you will need to list it explicitly:
Access-Control-Expose-Headers: *, Authorization
Specifications
Specification | Status | Comment |
---|---|---|
Fetch The definition of 'Access-Control-Expose-Headers' in that specification. | Living Standard |
Browser compatibility
BCD tables only load in the browser
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论