Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2017-10-23 17:37:54 +02:00
commit 50d3aa9333
3 changed files with 36 additions and 3 deletions

View File

@ -89,10 +89,14 @@ public abstract class BufferingResponseListener extends Listener.Adapter
{
media = contentType.substring(0, index);
String encoding = contentType.substring(index + charset.length());
// Sometimes charsets arrive with an ending semicolon
// Sometimes charsets arrive with an ending semicolon.
int semicolon = encoding.indexOf(';');
if (semicolon > 0)
encoding = encoding.substring(0, semicolon).trim();
// Sometimes charsets are quoted.
int lastIndex = encoding.length() - 1;
if (encoding.charAt(0) == '"' && encoding.charAt(lastIndex) == '"')
encoding = encoding.substring(1, lastIndex).trim();
this.encoding = encoding;
}

View File

@ -108,7 +108,36 @@ public class ContentResponseTest extends AbstractHttpClientServerTest
{
baseRequest.setHandled(true);
response.setHeader(HttpHeader.CONTENT_TYPE.asString(), contentType);
response.getOutputStream().write(content.getBytes("UTF-8"));
response.getOutputStream().write(content.getBytes(encoding));
}
});
ContentResponse response = client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.timeout(5, TimeUnit.SECONDS)
.send();
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(content, response.getContentAsString());
Assert.assertEquals(mediaType, response.getMediaType());
Assert.assertEquals(encoding, response.getEncoding());
}
@Test
public void testResponseWithContentTypeWithQuotedCharset() throws Exception
{
final String content = "The quick brown fox jumped over the lazy dog";
final String mediaType = "text/plain";
final String encoding = "UTF-8";
final String contentType = mediaType + "; charset=\"" + encoding + "\"";
start(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
baseRequest.setHandled(true);
response.setHeader(HttpHeader.CONTENT_TYPE.asString(), contentType);
response.getOutputStream().write(content.getBytes(encoding));
}
});

View File

@ -455,7 +455,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable
}
}
private class DumpKeys implements Runnable
private class DumpKeys extends NonBlockingAction
{
private final CountDownLatch latch = new CountDownLatch(1);
private final List<Object> _dumps;