lift / lift/framework

acceptsStarStar broken for weighted accept entries

Open
#1,186 1 comment 0 reactions 1 assignee Claimed by @dpp View on GitHub
P:Normal T:Defect WebKit
Dominant language
Scala
Stars
1.3k
Forks
275
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.