diff options
Diffstat (limited to 'files/zh-cn/web/http/headers/access-control-expose-headers/index.html')
-rw-r--r-- | files/zh-cn/web/http/headers/access-control-expose-headers/index.html | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/files/zh-cn/web/http/headers/access-control-expose-headers/index.html b/files/zh-cn/web/http/headers/access-control-expose-headers/index.html new file mode 100644 index 0000000000..93755fa0ca --- /dev/null +++ b/files/zh-cn/web/http/headers/access-control-expose-headers/index.html @@ -0,0 +1,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> |