Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of the "q" values in the HTTP "Accept" request header?

I have made a http request using Firefox.Now the request header shows the following:

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 

But curious to know what is q=0.9,*/*;q=0.8

like image 639
UVM Avatar asked May 08 '12 10:05

UVM


People also ask

What is Q in HTTP header?

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.

What is the purpose of the HTTP Accept 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.

What is the purpose of the accept field in an HTTP request?

The Accept request-header field can be used to specify certain media types which are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of a request for an in-line image.

What is the use of accept and Content-Type headers in HTTP request?

Accept header is used by HTTP clients to tell the server which type of content they expect/prefer as response. Content-type can be used both by clients and servers to identify the format of the data in their request (client) or response (server) and, therefore, help the other part interpret correctly the information.


2 Answers

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. The default value is q=1

The information is available here

A nice explanation can be found here as well.

like image 145
Eugene S Avatar answered Oct 22 '22 01:10

Eugene S


The Accept header list is first split at , then at ; for additional parameters per entry. So, the list in your example splits down to text/html, application/xhtml+xml, application/xml;q=0.9 and */*;q=0.8. The q= parameter on each entry indicates to the server the degree of preference for that media-type. It defaults to its maximum value of 1, if it is missing (like in the first 2 entries). The last entry of */*;q=0.8 indicates to the server, that eventually any content-type would be acceptable but would be less preferable than the others listed. Otherwise, the server might decide to send no content at all, because the client would not "accept" it anyway.

like image 26
Robin479 Avatar answered Oct 22 '22 01:10

Robin479