lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Fri, Sep 25, 2009 at 9:52 AM, Philippe Lhoste <> wrote:
> On 24/09/2009 18:59, Petite Abeille wrote:
>> Does anyone have a parser for HTTP q values (aka RFC 2616 3.9 Quality
>> Values) [1]?
>> E.g.:
>> image/gif, image/jpeg, text/html
>> image/gif;q=1.0, image/jpeg;q=0.8, image/png; q=1.0,*;q=0.1
>> gzip;q=1.0, identity; q=0.5, *;q=0
>> [1]
> I always wondered what is the real usage of these. The reference, which you
> are kind enough to provide, isn't very helpful. Is that fuzzy logic? :-)
> My understanding is that it expresses preferences of client about content
> the server can send, eg. in your example gzip content is preferred,

That is correct.

> uncompressed is fine, anything else is a no-no. Relatively simple. But the
> image formats is a bit more perplexing, I never saw a site offering to send
> Gif OR PNG image depending on browser preferences! :-)

The standard (http) permits this. It's rarely supported though. In
fact, you can't even rely on browsers to use it properly - IE is
really finicky about which headers it sends and when.

Anyway, the general idea is that if a resource (url) can respond with
different formats - say text/html and text/plain - the server can
compare the Accept header to the list of available formats and pick
the best match. The q value is used to weigh the candidates. If two
candidates have the same q value, their position in the list is used

I don't have a Lua library at hqand, but if you need a reference
implementation, I have implemented it for php, here: