506 Variant Also Negotiates
當內容協商在選擇資源的過程中出現遞迴迴圈時,HTTP 506 Variant Also Negotiates 伺服器錯誤響應狀態碼將被返回。
代理驅動的內容協商允許客戶端和伺服器在伺服器有多個變體時協同決定給定資源的最佳變體。伺服器傳送 506 狀態碼是由於伺服器配置錯誤導致建立響應時出現迴圈引用。
由於缺乏客戶端自動從響應中進行選擇的標準化方式,以及增加的往返時間會減慢客戶端-伺服器互動,因此這種機制很少使用。伺服器驅動的內容協商更為常見,在這種情況下,伺服器根據請求頭(Accept-Language、Accept 等)直接為客戶端選擇最合適的資源。
狀態
http
506 Variant Also Negotiates
示例
帶有變體的資源
在以下示例中,客戶端使用 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>
規範
| 規範 |
|---|
| RFC 2295 # section-8.1 |
另見
300 Multiple Choices- RFC 2295
- 內容協商
- HTTP 響應狀態碼
- Apache HTTP 伺服器文件中的內容協商
- Apache httpd
mod_negotiation.c原始碼顯示觸發HTTP_VARIANT_ALSO_VARIES響應的條件。