373037 jetty.server.Response.setContentLength(int) should not close a Writer when length=0

This commit is contained in:
Jan Bartel 2012-03-05 15:19:34 +11:00
parent 0c4450dc5d
commit 35a0386df0
2 changed files with 15 additions and 1 deletions

View File

@ -783,7 +783,7 @@ public class Response implements HttpServletResponse
if (isCommitted() || _connection.isIncluding())
return;
_connection._generator.setContentLength(len);
if (len>=0)
if (len>0)
{
_connection.getResponseFields().putLongField(HttpHeaders.CONTENT_LENGTH, len);
if (_connection._generator.isAllContentWritten())

View File

@ -439,6 +439,20 @@ public class ResponseTest
}
}
@Test
public void testZeroContent () throws Exception
{
Response response = new Response (new TestHttpConnection(connector, new ByteArrayEndPoint(), connector.getServer()));
PrintWriter writer = response.getWriter();
response.setContentLength(0);
assertTrue(!response.isCommitted());
assertTrue(!writer.checkError());
writer.print("");
assertTrue(!writer.checkError());
assertTrue(response.isCommitted());
}
@Test
public void testHead() throws Exception
{