Issue #1313 Send 500 if insufficient bytes not committed

This commit is contained in:
Greg Wilkins 2017-02-09 16:19:55 +11:00
parent 5015ed5173
commit 633b68dc72
2 changed files with 20 additions and 2 deletions

View File

@ -417,7 +417,12 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor
status == HttpStatus.NO_CONTENT_204 ||
status == HttpStatus.NOT_MODIFIED_304);
if (hasContent && !_response.isContentComplete(_response.getHttpOutput().getWritten()))
_transport.abort(new IOException("insufficient content written"));
{
if (isCommitted())
_transport.abort(new IOException("insufficient content written"));
else
_response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500,"insufficient content written");
}
}
_response.closeOutput();
_request.setHandled(true);

View File

@ -20,6 +20,7 @@ package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@ -442,10 +443,22 @@ public class HttpManyWaysToCommitTest extends AbstractHttpTest
server.start();
HttpTester.Response response = executeRequest();
assertThat("response has no status", response.getStatus(), is(0));
assertThat("response is error", response.getStatus(), is(500));
assertFalse("response not eof", response.isEarlyEOF());
}
@Test
public void testSetContentLengthAndFlushWriteInsufficientBytes() throws Exception
{
server.setHandler(new SetContentLengthAndWriteInsufficientBytesHandler(true));
server.start();
HttpTester.Response response = executeRequest();
assertThat("response has no status", response.getStatus(), is(200));
assertTrue("response eof", response.isEarlyEOF());
}
@Test
public void testSetContentLengthAndWriteExactlyThatAmountOfBytes() throws Exception
{