lua-users home
lua-l archive

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


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] http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.9

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, 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! :-) I was wondering about the meaning of 0.8 with regard to simple binary 0 vs. 1.0, but I realize these values can be used for sorting. I suppose using simple integers within defined bound would have been too simple... :-D

Anyway, I fear I have no direct answer to your question; should I do the job, I suppose I would turn to Lpeg... REs can be OK too, but perhaps it might be hard to handle all cases.
Or just a good old finite state machine...

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --