blob: 93755fa0ca79b063fbb49ab16630ef7824a6f96e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
---
title: Access-Control-Expose-Headers
slug: Web/HTTP/Headers/Access-Control-Expose-Headers
tags:
- 跨域资源共享
- 首部
translation_of: Web/HTTP/Headers/Access-Control-Expose-Headers
---
<div>{{HTTPSidebar}}</div>
<p>响应首部 <strong><code>Access-Control-Expose-Headers</code></strong> 列出了哪些首部可以作为响应的一部分暴露给外部。</p>
<p>默认情况下,只有七种 {{Glossary("Simple response header", "simple response headers")}} (简单响应首部)可以暴露给外部:</p>
<ul>
<li>{{HTTPHeader("Cache-Control")}}</li>
<li>{{HTTPHeader("Content-Language")}}</li>
<li>{{HTTPHeader("Content-Length")}}</li>
<li>{{HTTPHeader("Content-Type")}}</li>
<li>{{HTTPHeader("Expires")}}</li>
<li>{{HTTPHeader("Last-Modified")}}</li>
<li>{{HTTPHeader("Pragma")}}</li>
</ul>
<p>如果想要让客户端可以访问到其他的首部信息,可以将它们在 <code>Access-Control-Expose-Headers</code> 里面列出来。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Header type</th>
<td>{{Glossary("Response header")}}</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>no</td>
</tr>
</tbody>
</table>
<h2 id="语法">语法</h2>
<pre class="syntaxbox notranslate">Access-Control-Expose-Headers: <header-name>, <header-name>, ...
</pre>
<h2 id="指令">指令</h2>
<dl>
<dt><header-name></dt>
<dd>包含0个或多个除 {{Glossary("Simple response header", "simple response headers")}} (简单响应首部)之外的<a href="/en-US/docs/Web/HTTP/Headers">首部名称</a>列表,可以暴露给外部,供页面资源使用。</dd>
</dl>
<h2 id="示例">示例</h2>
<p>想要暴露一个非简单响应首部,可以这样指定:</p>
<pre class="notranslate">Access-Control-Expose-Headers: Content-Length</pre>
<p>想要额外暴露自定义的首部,例如 <code>X-Kuma-Revision</code>,可以指定多个,用逗号隔开:</p>
<pre class="notranslate">Access-Control-Expose-Headers: Content-Length, X-Kuma-Revision</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Fetch','#http-access-control-expose-headers', 'Access-Control-Expose-Headers')}}</td>
<td>{{Spec2("Fetch")}}</td>
<td></td>
</tr>
</tbody>
</table>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
<p>{{Compat("http.headers.Access-Control-Expose-Headers")}}</p>
<h2 id="关于兼容性的注意事项">关于兼容性的注意事项</h2>
<ul>
<li>在最新规范中提出的通配符(*),尚未被如下浏览器实现:
<ul>
<li>Chromium: <a href="https://bugs.chromium.org/p/chromium/issues/detail?id=615313">Issue 615313</a></li>
<li>Firefox: {{bug(1309358)}}</li>
<li>Servo: <a href="https://github.com/servo/servo/issues/13283">Issue 13283</a></li>
</ul>
</li>
</ul>
<h2 id="相关内容">相关内容</h2>
<ul>
<li>{{HTTPHeader("Access-Control-Allow-Headers")}}</li>
<li>{{HTTPHeader("Access-Control-Allow-Origin")}}</li>
</ul>
|