Disable onCommit after first commit
At times OnCommittedResponseWrapper#onResponseCommitted() can be invoked multiple times. For example, when flush is performed multiple times. This means that the session can be written multiple times which is inefficient. Instead, we should only save on the first update. Fixes gh-57
This commit is contained in:
@@ -28,7 +28,7 @@ public class OnCommittedResponseWrapperTests {
|
||||
@Mock
|
||||
ServletOutputStream out;
|
||||
|
||||
HttpServletResponse response;
|
||||
OnCommittedResponseWrapper response;
|
||||
|
||||
boolean committed;
|
||||
|
||||
@@ -1069,4 +1069,20 @@ public class OnCommittedResponseWrapperTests {
|
||||
|
||||
assertThat(committed).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bufferSizeCommitsOnce() throws Exception {
|
||||
String expected = "1234567890";
|
||||
when(response.getBufferSize()).thenReturn(expected.length());
|
||||
|
||||
response.getWriter().write(expected);
|
||||
|
||||
assertThat(committed).isTrue();
|
||||
|
||||
committed = false;
|
||||
|
||||
response.getWriter().write(expected);
|
||||
|
||||
assertThat(committed).isFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user