blob: 49ed46926277464197e858a01f2bd9029264a724 (
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
|
---
title: Connection
slug: Web/HTTP/Headers/Connection
tags:
- HTTP
- Web
- 参考
- 头部
translation_of: Web/HTTP/Headers/Connection
---
<div>{{HTTPSidebar}}</div>
<p><strong>Connection </strong>头(header) 决定当前的事务完成后,是否会关闭网络连接。如果该值是“keep-alive”,网络连接就是持久的,不会关闭,使得对同一个服务器的请求可以继续在该连接上完成。</p>
<div class="blockIndicator note">
<p> <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">特定于连接的标头字段(例如Connection)不得与HTTP / 2一起使用。</a></p>
</div>
<p>除去标准的逐段传输(hop-by-hop)头({{HTTPHeader("Keep-Alive")}}, {{HTTPHeader("Transfer-Encoding")}}, {{HTTPHeader("TE")}}, {{HTTPHeader("Connection")}}, {{HTTPHeader("Trailer")}}, {{HTTPHeader("Upgrade")}}, {{HTTPHeader("Proxy-Authorization")}} and {{HTTPHeader("Proxy-Authenticate")}}),任何逐段传输头都需要在 Connection 头中列出,这样才能让第一个代理知道必须处理它们且不转发这些头。标准的逐段传输头也可以列出(常见的例子是 {{HTTPHeader("Keep-Alive")}},但这不是必须的)。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Header type</th>
<td>{{Glossary("General header")}}</td>
</tr>
<tr>
<th scope="row">{{Glossary("Forbidden header name")}}</th>
<td>yes</td>
</tr>
</tbody>
</table>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">Connection: keep-alive
Connection: close
</pre>
<h2 id="指令">指令</h2>
<dl>
<dt><code>close</code></dt>
<dd>表明客户端或服务器想要关闭该网络连接,这是HTTP/1.0请求的默认值</dd>
<dt></dt>
<dt>以逗号分隔的HTTP头 [通常仅有 <code>keep-alive</code>]</dt>
<dd>表明客户端想要保持该网络连接打开,HTTP/1.1的请求默认使用一个持久连接。这个请求头列表由头部名组成,这些头将被第一个非透明的代理或者代理间的缓存所移除:这些头定义了发出者和第一个实体之间的连接,而不是和目的地节点间的连接。</dd>
<dt></dt>
</dl>
<h2 id="浏览器兼容性">浏览器兼容性</h2>
<p class="hidden">本页的兼容性表格是由结构数据生成的。如果您想为该数据做出贡献,请检出<a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> 并向我们发出拉取请求(pull request)</p>
<div>{{Compat("http.headers.Connection")}}</div>
|