506 變體協商
HTTP 506 Variant Also Negotiates 伺服器錯誤響應 狀態碼在透明內容協商 (TCN) 過程中返回,當在選擇資源的過程中存在遞迴迴圈時。
透明內容協商允許客戶端和伺服器在伺服器具有多個變體時協作決定給定資源的最佳變體。伺服器由於伺服器錯誤配置導致在建立響應時產生迴圈引用而傳送 506 狀態碼。
由於實現的複雜性、客戶端自動從響應中選擇的方式缺乏標準化以及導致客戶端-伺服器互動速度變慢的額外往返次數,大多數現代瀏覽器都不支援透明內容協商。 伺服器驅動內容協商 遠更為常見,其中伺服器根據請求頭(Accept-Language、Accept 等)直接為客戶端選擇最合適的資源。
狀態
http
506 Variant Also Negotiates
規範
| 規範 |
|---|
| RFC 2295 # 第 8.1 節 |
示例
具有變體的資源
在以下示例中,客戶端使用 Accept-Language 標頭請求 fr 語言環境中的頁面。這可以使用 curl 執行
bash
curl -H "Negotiate: trans" -H "Accept-Language: fr;" http://example.com/index
這會產生以下請求
http
GET /index HTTP/1.1
Host: example.com
User-Agent: curl/8.7.1
Accept: */*
Negotiate: trans
Accept-Language: fr
由於伺服器錯誤配置,fr 的變體響應指向一個 型別對映,它本身會導致執行透明協商。伺服器可以透過在傳送之前在選擇響應中存在 TCN 標頭來檢測此條件
http
HTTP/1.1 506 Variant Also Negotiates
Date: Mon, 22 Jul 2024 10:00:00 GMT
Server: Apache/2.4.41 (Unix)
Content-Type: text/html; charset=UTF-8
Content-Length: 233
TCN: list
Vary: negotiate,accept-language
Alternates: {"index.html.en" 1 {type text/html} {language en} {length 48}}, {"another-map.html.fr.map" 1 {type text/html} {language fr} {length 45}}}}
<html>
<head>
<title>506 Variant Also Negotiates</title>
</head>
<body>
<h1>Variant Also Negotiates</h1>
<p>A variant for the requested resource is itself a negotiable resource. This indicates a configuration error.</p>
</body>
</html>
另請參閱
300 Multiple Choices- RFC 2295
- 內容協商
- HTTP 響應狀態碼
- Apache HTTP Server 文件中的內容協商
- Apache httpd
mod_negotiation.c原始碼 顯示觸發HTTP_VARIANT_ALSO_VARIES響應的條件。