users@jsr311.java.net

Re: Sorting accept media types

From: Marc Hadley <Marc.Hadley_at_Sun.COM>
Date: Thu, 26 Feb 2009 16:59:58 -0500

On Feb 26, 2009, at 5:04 AM, Sergey Beryozkin wrote:
>
> If we have
>
> Accept : text/plain,text/xml;q=0.9, */*
>
> and two methods with one producing text/xml and another one
> application/pdf then what format has to be returned ?
>
> text/xml is more specific than */* but */* has a quality factor 1.0.
> JAXRS specification says a quality factor is a primary key, but in
> this case it does seem correct to return text/xml, is it correct ?
>
The method chosen, all else being equal, is determined by 3.7.2 3(b)
which punts to section 14.1 or RFC 2616. In the example you give I
think that would be application/pdf since the implied q-value is 1 vs
0.9 for text/xml.

This does seem unintuitive and Apache can cook Accept header values to
compensate, see "Fiddling with Quality Values":

http://httpd.apache.org/docs/1.3/content-negotiation.html

>
> Another question :
>
> Accept : application/pdf;q=0.9, text/*
>
> text/* is more specific than */* but it's still less specifc than
> application/pdf. Its quality factor is 1.0 though. So is it text/xml
> format (given the example with 2 methods above) that has to be
> returned ?
>
If there are two methods, one producing application/pdf and the other
text/xml then I think the text/xml one should be chosen all else being
equal.

Marc.