Browse Source

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-7261
pull/7949/head
Daniel Wegener 7 years ago committed by Josh Cummings
parent
commit
f28fe2d501
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
  1. 6
      web/src/main/java/org/springframework/security/web/util/OnCommittedResponseWrapper.java
  2. 11
      web/src/test/java/org/springframework/security/web/util/OnCommittedResponseWrapperTests.java

6
web/src/main/java/org/springframework/security/web/util/OnCommittedResponseWrapper.java

@ -69,6 +69,12 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap @@ -69,6 +69,12 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
super.setContentLength(len);
}
@Override
public void setContentLengthLong(long len) {
setContentLength(len);
super.setContentLengthLong(len);
}
private void setContentLength(long len) {
this.contentLength = len;
checkContentLength(0);

11
web/src/test/java/org/springframework/security/web/util/OnCommittedResponseWrapperTests.java

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

Loading…
Cancel
Save