We fixed some of this with Jetty 9.1.x.
Know that UpgradeRequest is the exposed API, unwrapping and digging into the jetty specifics is not a long term, future-proof approach.
You could do something like this (notice that this only uses java classes + websocket api classes + junit)
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
import org.junit.Test;
public class AcceptLanguagesTest
{
public static class QualityValue implements Comparable<QualityValue>
{
public String value;
public double quality;
public QualityValue(String value, double quality)
{
this.value = value;
this.quality = quality;
}
@Override
public int compareTo(QualityValue o)
{
return (int)((o.quality * 100) - (this.quality * 100));
}
@Override
public String toString()
{
return String.format("%s [quality=%.1f]",value,quality);
}
}
@Test
public void testAcceptLanguages()
{
String acceptLangs = "tr-tr,tr;q=0.8,en-us;q=0.5,en;q=0.3";
System.out.printf("--] %s%n", acceptLangs);
List<QualityValue> values = parseQualityValues(acceptLangs);
for (QualityValue value : values)
{
System.out.println(value);
}
}
@Test
public void testAcceptLanguagesOdd()
{
String acceptLangs = "tr-tr,tr;q=0.2,en-us;q=0.9,en;q=0.3";
System.out.printf("--] %s%n", acceptLangs);
List<QualityValue> values = parseQualityValues(acceptLangs);
for (QualityValue value : values)
{
System.out.println(value);
}
}
private List<QualityValue> parseQualityValues(String raw)
{
List<QualityValue> ret = new ArrayList<>();
Iterator<String> parts = QuoteUtil.splitAt(raw,",");
while (parts.hasNext())
{
String part = parts.next();
String value = null;
double quality = 1.0;
Iterator<String> qs = QuoteUtil.splitAt(part,";");
while (qs.hasNext())
{
String q = qs.next();
if (q.startsWith("q"))
{
int idx = q.indexOf('=');
if (idx > 0)
{
quality = Double.parseDouble(q.substring(idx + 1));
}
}
else
{
value = q;
}
}
if (value == null)
{
value = part;
}
ret.add(new QualityValue(value,quality));
}
Collections.sort(ret);
return ret;
}
}
Output from this testcase ...
Now, that being said, exposing either a ..
sounds like a reasonable feature / enhancement request.