Do not commit response on access to content

MockHttpServletResponse no longer calls flushBuffer on calls to
getContentAsByteArray and getContentAsString. The flushing doesn't
actually do anything useful but does commit the response leading to
unexpected side effects.

Issue: SPR-16430
master
Rossen Stoyanchev 7 years ago
parent cd57335e46
commit 6d909b013e
  1. 4
      spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java
  2. 4
      spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -199,12 +199,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
public byte[] getContentAsByteArray() {
flushBuffer();
return this.content.toByteArray();
}
public String getContentAsString() throws UnsupportedEncodingException {
flushBuffer();
return (this.characterEncoding != null ?
this.content.toString(this.characterEncoding) : this.content.toString());
}

@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@ -192,12 +192,10 @@ public class MockHttpServletResponse implements HttpServletResponse {
}
public byte[] getContentAsByteArray() {
flushBuffer();
return this.content.toByteArray();
}
public String getContentAsString() throws UnsupportedEncodingException {
flushBuffer();
return (this.characterEncoding != null ?
this.content.toString(this.characterEncoding) : this.content.toString());
}

Loading…
Cancel
Save