如何处理 accept-language 回退?

How to handle accept-language fallback?

使用 Accept-Language header 中的区域设置回退的正确方法是什么?在从区域设置中删除任何子标签(区域等)之前,应用程序是否应该尝试完美匹配所有请求的区域设置?或者它应该以相反的方式发生,即使请求中不存在那些 region-less 语言环境? HTTP spec 没有给出任何指示。

RFC 2616 已被 2014 年的 RFC 7230 至 7235 废弃。请不要再参考它。通过新的 RFC,Accept-Language header 现在受 RFC 7231, section 5.3.5. Said section is referring to RFC 4647, section 3.3, which has already been authorative over RFC 2616. Furthermore, RFC 7231 makes it clear that the "Basic Filtering" matching strategy is to be used which is described in detail in RFC 4647, section 3.3.1.

的授权

基本过滤或多或少是一种前缀搜索。但是请注意,此搜索正在查找 syntactical 前缀,而不是 lexical 前缀。应用程序应该按照质量的降序(如果没有提供质量,这是客户端提供的顺序)检查请求的语言标签列表,并查看每个标签是否可以得到满足。如果可以统计 none,RFC 7231 指出:

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.

相关部分确实强调忽略语言要求是更明智的做法。