OnCommitedResponseWrapper commits when buffer exceeded

Fixes #26
This commit is contained in:
Rob Winch
2014-08-01 14:38:24 -05:00
parent 0d217c680a
commit 2732a183f3
2 changed files with 14 additions and 1 deletions

View File

@@ -187,7 +187,10 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
*/
private void checkContentLength(long contentLengthToWrite) {
contentWritten += contentLengthToWrite;
if(contentLength > 0 && contentWritten >= contentLength) {
boolean isBodyFullyWritten = contentLength > 0 && contentWritten >= contentLength;
int bufferSize = getBufferSize();
boolean requiresFlush = bufferSize > 0 && contentWritten >= bufferSize;
if(isBodyFullyWritten || requiresFlush) {
doOnResponseCommitted();
}
}

View File

@@ -1059,4 +1059,14 @@ public class OnCommittedResponseWrapperTests {
assertThat(committed).isTrue();
}
@Test
public void bufferSizePrintWriterWriteCommits() throws Exception {
String expected = "1234567890";
when(response.getBufferSize()).thenReturn(expected.length());
response.getWriter().write(expected);
assertThat(committed).isTrue();
}
}