506 Variant Also Negotiates

当内容协商在选择资源的过程中出现递归循环时,HTTP 506 Variant Also Negotiates 服务器错误响应状态码将被返回。

代理驱动的内容协商允许客户端和服务器在服务器有多个变体时协同决定给定资源的最佳变体。服务器发送 506 状态码是由于服务器配置错误导致创建响应时出现循环引用。

由于缺乏客户端自动从响应中进行选择的标准化方式,以及增加的往返时间会减慢客户端-服务器交互,因此这种机制很少使用。服务器驱动的内容协商更为常见,在这种情况下,服务器根据请求头(Accept-LanguageAccept 等)直接为客户端选择最合适的资源。

状态

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

另见