44

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.

DanMan
  • 11,323
  • 4
  • 40
  • 61
mckamey
  • 17,359
  • 16
  • 83
  • 116

2 Answers2

43

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

Gumbo
  • 643,351
  • 109
  • 780
  • 844
  • 1
    So to clarify, the `;q=0.9` only applies to `text/html` in the example? And as a corollary, `image/png` is also `q=1`? – mckamey Mar 16 '11 at 20:44
  • 2
    I read the RFC but found it to be ambiguous, hence the question. So does the media-range fully end at each '`,`'? – mckamey Mar 16 '11 at 20:46
  • 17
    There is a nice blog article on accept headers here: http://www.gethifi.com/blog/browser-rest-http-accept-headers Amongst other things the OP's question is adressed – Simen S Mar 16 '11 at 20:52
0

Verbally,this would be interpreted as "application/xml,application/xhtml+xml and image/png are the preferred media types,but if they do not exist,then send the text/html entity,and if that does not exist,send the text/plain entity,if that still does not exist,send an an entity with any other media type."

周汉成
  • 1,217
  • 2
  • 13
  • 24