Skip to content

Commit

Permalink
Issue #5539 - Updating StatisticsServlet accept processing per review
Browse files Browse the repository at this point in the history
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
  • Loading branch information
joakime committed Nov 16, 2020
1 parent 770be2d commit 683d9a9
Showing 1 changed file with 16 additions and 19 deletions.
Expand Up @@ -39,6 +39,7 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.QuotedQualityCSV;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.server.AbstractConnector;
Expand Down Expand Up @@ -212,40 +213,36 @@ private void writeJsonResponse(HttpServletResponse response) throws IOException

private List<String> getOrderedAcceptableMimeTypes(HttpServletRequest request)
{
QuotedQualityCSV values = null;
Enumeration<String> enumAccept = request.getHeaders("Accept");
QuotedQualityCSV values = new QuotedQualityCSV(QuotedQualityCSV.MOST_SPECIFIC_MIME_ORDERING);

// No accept header specified, try 'accept' parameter (for those clients that are
// so ancient that they cannot set the standard HTTP `Accept` header)
String acceptParameter = request.getParameter("accept");
if (acceptParameter != null)
{
values.addValue(acceptParameter);
}

Enumeration<String> enumAccept = request.getHeaders(HttpHeader.ACCEPT.toString());
if (enumAccept != null)
{
while (enumAccept.hasMoreElements())
{
String value = enumAccept.nextElement();
if (StringUtil.isNotBlank(value))
{
if (values == null)
{
values = new QuotedQualityCSV(QuotedQualityCSV.MOST_SPECIFIC_MIME_ORDERING);
}
values.addValue(value);
}
}
}

if (values != null)
{
return values.getValues();
}

// No accept header specified, try 'accept' parameter (for those clients that are
// so ancient that they cannot set the standard HTTP `Accept` header)
String acceptParameter = request.getParameter("accept");
if (acceptParameter != null)
if (values.isEmpty())
{
// return that we support the one type specified in the 'accept' parameter
return Collections.singletonList(acceptParameter);
// return that we allow ALL mime types
return Collections.singletonList("*/*");
}

// return that we allow ALL mime types
return Collections.singletonList("*/*");
return values.getValues();
}

private boolean isLoopbackAddress(String address)
Expand Down

0 comments on commit 683d9a9

Please sign in to comment.