Skip to content

Commit

Permalink
OnCommitedResponseWrapper commits when buffer exceeded
Browse files Browse the repository at this point in the history
Fixes #26
  • Loading branch information
Rob Winch committed Aug 1, 2014
1 parent 0d217c6 commit 2732a18
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ private void trackContentLength(String content) {
*/
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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1059,4 +1059,14 @@ public void addHeaderContentLengthPrintWriterWriteStringCommits() throws Excepti

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();
}
}

0 comments on commit 2732a18

Please sign in to comment.