Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is q=0.5 in Accept* HTTP headers?

People also ask

What is Q in HTTP header?

The 'q' Parameter Sometimes clients may want to set their preferences when requesting multiple MIME types. To set this preference, q parameter (relative quality factor) is used. Value of q parameter can be from 0 to 1. 0 is the lowest value (i.e. least preferred) and 1 is the highest (i.e. most preferred).

What is accept in HTTP header?

The Accept request HTTP header indicates which content types, expressed as MIME types, the client is able to understand. The server uses content negotiation to select one of the proposals and informs the client of the choice with the Content-Type response header.

Is HTTP Accept header required?

Servers may ignore the Accept header. If you're not returning anything in your response, it's kind of meaningless. It's up to you to decide whether you want to reject requests with Accept headers or not.


This is called a relative quality factor. It specifies what language the user would prefer, on a scale of 0 to 1, as can be seen from the HTTP/1.1 Specification, §14.4:

Each language-range MAY be given an associated quality value which represents an estimate of the user's preference for the languages specified by that range. The quality value defaults to "q=1". For example,

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

would mean: "I prefer Danish, but will accept British English and other types of English."


It is called the relative quality factor in the specification:

Each media-range MAY be followed by one or more accept-params, beginning with the "q" parameter for indicating a relative quality factor. The first "q" parameter (if any) separates the media-range parameter(s) from the accept-params. Quality factors allow the user or user agent to indicate the relative degree of preference for that media-range, using the qvalue scale from 0 to 1 (section 3.9). The default value is q=1.

...

The example

Accept: audio/*; q=0.2, audio/basic

SHOULD be interpreted as "I prefer audio/basic, but send me any audio type if it is the best available after an 80% mark-down in quality."

See also:

  • HTTP/1.1: Header Field Definitions

Accept-languages quality parameter can be understood like this:

by attaching Accept-Language: pl_PL;q=0.8, en_US;q=0.2, header to the request we communicate to the server following message

Server, please provide me Polish translation of this website, but please do that only if its quality is >= %80% of related-quality-factor. In case quality is <80% - I do not mind getting the English version, because it is irrelevant for me since I speak English anyway.

So for example, as a web page content provider we might introduce Accept-Language header parsing in such a way, that our website is suitable for foreigners speaking no English at all (then even translated navigation would be helpful (pages having translated only the navigation, lets say, have q=0.1), where fully translated content has q=0.9 and fully translated content and verified by native speakers speaking both original language and translated language content might have q=0.99 - because this is the only possible situation when meaning of the content is fully transduced)