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";