From 51252a55e68e486801473c5f9a4d3b1292971174 Mon Sep 17 00:00:00 2001 From: Josh Cummings Date: Tue, 20 Aug 2019 13:29:52 -0600 Subject: [PATCH] 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 --- .../web/http/OnCommittedResponseWrapper.java | 8 +++++++- .../web/http/OnCommittedResponseWrapperTests.java | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java b/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java index f08b012b..6691d277 100644 --- a/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java +++ b/spring-session-core/src/main/java/org/springframework/session/web/http/OnCommittedResponseWrapper.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2018 the original author or authors. + * Copyright 2014-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -68,6 +68,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); diff --git a/spring-session-core/src/test/java/org/springframework/session/web/http/OnCommittedResponseWrapperTests.java b/spring-session-core/src/test/java/org/springframework/session/web/http/OnCommittedResponseWrapperTests.java index 716b3ab2..0cbcec4c 100644 --- a/spring-session-core/src/test/java/org/springframework/session/web/http/OnCommittedResponseWrapperTests.java +++ b/spring-session-core/src/test/java/org/springframework/session/web/http/OnCommittedResponseWrapperTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2017 the original author or authors. + * Copyright 2014-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1102,6 +1102,17 @@ public 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 public void bufferSizeCommitsOnce() throws Exception { String expected = "1234567890";