HTTP header `Accept-Language` :服务器应该严格使用它还是仅作为偏好使用它?

HTTP header `Accept-Language` : Should servers use it strictly or just as a preference?

我想知道服务器应该如何使用 HTTP header "Accept Language" 以防服务器有请求的资源但不是指定的语言。服务器是否应该 return 任何类型的错误(404 或 "resource not found" 等)或成功但可用语言的资源?

HTTP 规范是否提及或推荐这种情况下的用法?
我读了 "RFC2616 - 14.4 Accept-Language" 但我不是很清楚。

我知道快速的解决方案是将 Accept Language: * 添加到 header 但我想了解这里的内容并尝试在右侧解决这个问题(可能是服务器或客户端)

感谢任何帮助。

首先,RFC 2616 已弃用,您应该参考 RFC 7230–7235。

RFC 7231 – 5.3.5. Accept-Language中您可以阅读:

If the header field is present in a request and none of the available representations for the response have a matching language tag, the origin server can either disregard the header field by treating the response as if it is not subject to content negotiation or honor the header field by sending a 406 (Not Acceptable) response. However, the latter is not encouraged, as doing so can prevent users from accessing content that they might be able to use (with translation software, for example).

因此要么忽略 header 并使用默认语言表示进行响应。或者将请求回复为不可接受,作者不鼓励这样做。但是,您可以使用 406 响应来提供可用语言表示的列表。