Mumfi
Mumfi

Reputation: 425

Significance of different q values in Accept-Language header

In a http GET request, If I have understood things correctly, the q value for Accept-Language lists the language priority in the response.

From this link:

Accept-Language: da, en-gb;q=0.8, en;q=0.7

Danish is preferred. If that fails, British English is requested, and finally any type of English.

Why does the actual value matter if it is just a matter of priority?

In this example, what difference would it make if it instead read:

Accept-Language: da, en-gb:q=0.5, en:q=0.4

?

Upvotes: 4

Views: 2227

Answers (1)

Sinthorion
Sinthorion

Reputation: 327

The Accept-headers are used for server-driven content negotiation. The HTTP specification does not specify what to do with the quality values, only that a higher value is more preferred by the agent. Everything else is left to decide for the server.

The idea is further explored and explained here. This assumes the original quality of a resource to be 1, and each operation done on it (such as translating or converting to a different format) to degrade it. Other factors considered are time (needed by the server to do operations to produce a better resource) and size (less efficient formats).

Time and size are usually irrelevant to languages. Instead, the quality (ie. completeness) of the available translation could be used. For example if the Danish translation is only 60% complete, then the English translation would be preferred for the header Accept-Language: da, en-gb;q=0.8, en;q=0.7 but not for Accept-Language: da, en-gb:q=0.5, en:q=0.4.

In practice, however, the quality values seem to have no purpose at all nowadays. I tested many popular websites (including Google and Facebook) in Firefox using the custom header Accept-Language: fr;q=0.5, en, which would mean I prefer English over French. All websites I tested returned a French page. I also swapped 'fr' and 'en' and got only English pages. That means modern websites seem to completely ignore the quality value and only use the order of languages in the header. It's unusual to have the options not in order of preference, but it does not violate the specification.

(I cleared all cookies before each test and I don't live in a French-speaking country nor do I use French anywhere on my computer, so that can have no effect on the results.)

Upvotes: 3

Related Questions