Merged branch 'jetty-9.4.x' into 'master'.
This commit is contained in:
commit
50d3aa9333
|
@ -89,10 +89,14 @@ public abstract class BufferingResponseListener extends Listener.Adapter
|
||||||
{
|
{
|
||||||
media = contentType.substring(0, index);
|
media = contentType.substring(0, index);
|
||||||
String encoding = contentType.substring(index + charset.length());
|
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(';');
|
int semicolon = encoding.indexOf(';');
|
||||||
if (semicolon > 0)
|
if (semicolon > 0)
|
||||||
encoding = encoding.substring(0, semicolon).trim();
|
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;
|
this.encoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,36 @@ public class ContentResponseTest extends AbstractHttpClientServerTest
|
||||||
{
|
{
|
||||||
baseRequest.setHandled(true);
|
baseRequest.setHandled(true);
|
||||||
response.setHeader(HttpHeader.CONTENT_TYPE.asString(), contentType);
|
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));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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 CountDownLatch latch = new CountDownLatch(1);
|
||||||
private final List<Object> _dumps;
|
private final List<Object> _dumps;
|
||||||
|
|
Loading…
Reference in New Issue