| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
HTTP Content Negotiation and "Quality Values" (Page 3 of 3) Weighting Preferences with "Quality Values" Even better than simple acceptance lists, HTTP allows the client to weight each of the items in such a list, to indicate which is preferred of the alternatives. This is done by adding a decimal quality value after each parameter using the syntax q=<value>, which represents the relative priority of that parameter relative to others. The highest priority is 1 and the lowest is 0; the default if no value is indicated is 1, while a value of 0 means the client is specifically saying it is not willing to accept documents with that characteristic. This is best illustrated by an example, so lets take our trilingual friend again. This time, lets say she knows English, French and Spanish, but her French is a bit rusty (she hasnt used it in a while). Furthermore, she may need to share this document with a friend of hers who only knows a little Spanish, so it would be best if she got the document in English. Finally, she knows there is a German version of the resource that she definitely does not want. This could be represented as follows: Accept-Language: en, fr;q=0.3, sp;q=0.7, de;q=0 Translated to English, this means I prefer if you sent me the document in English. If not, Spanish is okay, or French if that is all you have, but definitely dont send it in German. Incidentally, the name quality value is the one used in the HTTP standard, but is really a poor choice of terminology (which, to be fair, is also mentioned in the standard!) These values do not really have anything to do with quality; for all we know, the German version of this document may be the original and the others could be lousy translations. The q values only specify the relative preference of the client making the request. Finally, the * wildcard can be used in the Accept family of headers to represent any value, or everything else. This is often used to tell the server if you cant find what I specifically asked for, then heres my preference level on the alternatives. Lets take an example using the Accept header: Accept: text/html, text/*;q=0.6, */*;q=0.1 This header represents the client saying My preference (q=1) is an HTML text document. If not available, I would prefer some other type of text document. Failing that, you may send me any other type of document relevant to the requested resource.
Home - Table Of Contents - Contact Us The TCP/IP Guide (http://www.TCPIPGuide.com) Version 3.0 - Version Date: September 20, 2005 © Copyright 2001-2005 Charles M. Kozierok. All Rights Reserved. Not responsible for any loss resulting from the use of this site. |