OnCommittedResponseWrapper tracks getOutputStream().write(byte[]) properly

Fixes gh-171
This commit is contained in:
Rob Winch
2015-03-10 00:29:03 -05:00
parent 72227b8d83
commit 2d8664d841
2 changed files with 23 additions and 0 deletions

View File

@@ -155,6 +155,10 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
trackContentLength(String.valueOf(content));
}
private void trackContentLength(byte[] content) {
checkContentLength(content == null ? 0 : content.length);
}
private void trackContentLength(char[] content) {
checkContentLength(content == null ? 0 : content.length);
}

View File

@@ -882,6 +882,25 @@ public class OnCommittedResponseWrapperTests {
assertThat(committed).isTrue();
}
// gh-171
@Test
public void contentLengthPlus1OutputStreamWriteByteArrayMultiDigitCommits() throws Exception {
String expected = "{\n" +
" \"parameterName\" : \"_csrf\",\n" +
" \"token\" : \"06300b65-c4aa-4c8f-8cda-39ee17f545a0\",\n" +
" \"headerName\" : \"X-CSRF-TOKEN\"\n" +
"}";
response.setContentLength(expected.length() + 1);
response.getOutputStream().write(expected.getBytes());
assertThat(committed).isFalse();
response.getOutputStream().write("1".getBytes("UTF-8"));
assertThat(committed).isTrue();
}
@Test
public void contentLengthOutputStreamPrintBooleanCommits() throws Exception {
boolean b = true;