blob: 8deca4720cad85e13e25e4e129c7c19fae5b56e4 (
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
|
---
title: Connection
slug: Web/HTTP/Headers/Connection
tags:
- HTTP
- Headers
- Reference
- Web
---
<div>{{HTTPSidebar}}</div>
<p><strong><code>Connection</code></strong> 標頭用來控制在本次事務(transaction)後,連線是否要繼續開著。如果設定為 <code>keep-alive</code> ,
則連線繼續開著,讓接下來送往同一伺服器的請求利用。</p>
<div class="notecard warning">
<p>Connection 相關的標頭如 {{HTTPHeader("Connection")}} 和
{{HTTPHeader("Keep-Alive")}} 在 <a
href="https://datatracker.ietf.org/doc/html/rfc7540#section-8.1.2.2">HTTP/2 中被禁用</a>。
Chrome 和 Firefox 會忽略 HTTP/2 回應中的這些標頭,不過 Safari 遵守 HTTP/2
spec 的要求,不會讀取包含這些標頭的回應內容。</p>
</div>
<p>除了標準的點對點標頭(hop-by-hop headers)({{HTTPHeader("Keep-Alive")}} 、
{{HTTPHeader("Transfer-Encoding")}} 、 {{HTTPHeader("TE")}} 、 {{HTTPHeader("Connection")}} 、
{{HTTPHeader("Trailer")}} 、 {{HTTPHeader("Upgrade")}} 、
{{HTTPHeader("Proxy-Authorization")}} 以及 {{HTTPHeader("Proxy-Authenticate")}}),
任何在 HTTP 事務中使用到的點對點標頭都必須在 <code>Connection</code> 標頭列出來,
這樣首先經手請求的代理軟體才知道自己要處理這些標頭。標準的點對點標頭也是一樣的處理方式。</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="Syntax">語法</h2>
<pre class="brush: html">Connection: keep-alive
Connection: close
</pre>
<h2 id="Directives">指令</h2>
<dl>
<dt><code>close</code></dt>
<dd>表示客戶端或伺服器想要關閉連線。
通常用在 HTTP/1.0 。</dd>
<dt>一串用逗號分隔的 HTTP 標頭 [通常只設定為 <code>keep-alive</code> ]</dt>
<dd>表示客戶端想要讓連線持續開著。HTTP/1.1 請求的預設行為就是維持連線開啟。
至於那串用逗號分隔的 HTTP 標頭會被首先經手請求的代理軟體或快取軟體移除:因為這些標頭就是用來控制請求發起者與第一個代理軟體的連線行為,而不是請求的目標伺服器。</dd>
</dl>
<h2 id="Browser_compatibility">瀏覽器相容性</h2>
<p>{{Compat("http.headers.Connection")}}</p>
|