Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP Accept Header meaning

When a browser's Accept request header says something like the following:

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

Does that mean that application/xml, application/xhtml+xml, and text/html all have a quality param of 0.9?

Or does it mean that application/xml and application/xhtml+xml have the default (q=1) and text/html has the q=0.9 param?

I'm assuming the former, but was hoping someone knew more definitively.

like image 697
mckamey Avatar asked Mar 16 '11 20:03

mckamey


People also ask

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. But I think most systems will not reject these requests.

What is the purpose of accept in HTTP?

14.1 Accept 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 Web API Accept header?

The Accept header attribute specifies the format of response data which the client expects and the Content-Type header attribute specifies the format of the data in the request body so that receiver can parse it into appropriate format.


1 Answers

No, if the quality parameter is missing q=1.0 is assumed:

Each media-range MAY be followed by one or more accept-params, beginning with the "q" parameter for indicating a relative quality factor […] using the qvalue scale from 0 to 1 (section 3.9). The default value is q=1.

So the given value is to be interpreted as: “application/xml, application/xhtml+xml, and image/png are the preferred media types, but if they don’t exist, then send the text/html entity (text/html;q=0.9), and if that doesn’t exist, then send the text/plain entity (text/plain;q=0.8), and if that doesn’t exist, send an entity with any other media type (*/*;q=0.5).”

like image 137
Gumbo Avatar answered Sep 23 '22 17:09

Gumbo