httphttp-headershttp-accept-language

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


I wonder how servers should use HTTP header "Accept Language" in case the server has the requested resource but not in the language specified. Should the server return an error of any kind (404, or "resource not found", etc) or success but resource in the available language?

Does the HTTP specification mentions or recommends the usage in this case?
I read "RFC2616 - 14.4 Accept-Language" but It was not very clear to me.

I know the quick solution would be to add Accept Language: * to the header but I want to learn what is right here and try to solve this in the right side (maybe server or maybe client)

Any help is appreciated.


Solution

  • First of all, RFC 2616 is deprecated and you should refer to RFC 7230–7235 instead.

    In RFC 7231 – 5.3.5. Accept-Language you can read:

    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).

    So either ignore the header and respond with the default language representation. Or respond to the request as not acceptable, which is not encouraged by the authors. However, you could use the 406 response to provide a list of available language representations.