Add OnCommittedResponseWrapper.setContentLengthLong

Add setContentLengthLong tracking to OnCommittedResponseWrapper in
order to detect commits on servlets that use setContentLengthLong to
announce the entity size they are about to write (as used in the
Apache Tomcat's DefaultServlet).

Fixes gh-1489
This commit is contained in:
Josh Cummings
2019-08-20 13:29:52 -06:00
parent 5d26ab4df4
commit bcdd05a0bc
2 changed files with 17 additions and 0 deletions

View File

@@ -69,6 +69,12 @@ abstract class OnCommittedResponseWrapper extends HttpServletResponseWrapper {
super.addHeader(name, value);
}
@Override
public void setContentLengthLong(long len) {
setContentLength(len);
super.setContentLengthLong(len);
}
@Override
public void setContentLength(int len) {
setContentLength((long) len);

View File

@@ -1100,6 +1100,17 @@ class OnCommittedResponseWrapperTests {
assertThat(this.committed).isTrue();
}
// gh-7261
@Test
void contentLengthLongOutputStreamWriteStringCommits() throws IOException {
String body = "something";
this.response.setContentLengthLong(body.length());
this.response.getOutputStream().print(body);
assertThat(this.committed).isTrue();
}
@Test
void bufferSizeCommitsOnce() throws Exception {
String expected = "1234567890";