acceptsStarStar broken for weighted accept entries
I have a simple feed that uses serveJx to select the return type (json
or xml) based on the request Accept header and the extension (.json
or .xml). This generally works fine except in one case I've found. If
the extension is .xml, I get back json. I have traced this back to a
bug in Req.acceptsStarStar in version 2.4-M4, which looks like this:
lazy val acceptsStarStar : Boolean = accepts.map(_ == "*/*") openOr
false
In my case accepts = Full(text/html,application/xhtml+xml,application/
xml;q=0.9,*/*;q=0.8). Note that the last entry is weighted. Thus, the
above comparison to "*/*" fails and acceptsStarStar returns false,
when in fact it should be true because "*/*" is present, just with a
weight, which is a valid format (see weightedAccepts in Req).
The full call stack is:
serveJx
jxSel
jsonResponse_?
acceptsStarStar
Weighted accept is List(ContentType(text,html,0,Empty,List()),
ContentType(application,xhtml+xml,1,Empty,List()),
ContentType(application,xml,2,Full(0.9),List()), ContentType(*,*,
3,Full(0.8),List()))
Thanks.
or xml) based on the request Accept header and the extension (.json
or .xml). This generally works fine except in one case I've found. If
the extension is .xml, I get back json. I have traced this back to a
bug in Req.acceptsStarStar in version 2.4-M4, which looks like this:
lazy val acceptsStarStar : Boolean = accepts.map(_ == "*/*") openOr
false
In my case accepts = Full(text/html,application/xhtml+xml,application/
xml;q=0.9,*/*;q=0.8). Note that the last entry is weighted. Thus, the
above comparison to "*/*" fails and acceptsStarStar returns false,
when in fact it should be true because "*/*" is present, just with a
weight, which is a valid format (see weightedAccepts in Req).
The full call stack is:
serveJx
jxSel
jsonResponse_?
acceptsStarStar
Weighted accept is List(ContentType(text,html,0,Empty,List()),
ContentType(application,xhtml+xml,1,Empty,List()),
ContentType(application,xml,2,Full(0.9),List()), ContentType(*,*,
3,Full(0.8),List()))
Thanks.
Leave a comment