Skip to content

Commit 6d909b0

Browse files
committed
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
1 parent cd57335 commit 6d909b0

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

spring-test/src/main/java/org/springframework/mock/web/MockHttpServletResponse.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -199,12 +199,10 @@ public PrintWriter getWriter() throws UnsupportedEncodingException {
199199
}
200200

201201
public byte[] getContentAsByteArray() {
202-
flushBuffer();
203202
return this.content.toByteArray();
204203
}
205204

206205
public String getContentAsString() throws UnsupportedEncodingException {
207-
flushBuffer();
208206
return (this.characterEncoding != null ?
209207
this.content.toString(this.characterEncoding) : this.content.toString());
210208
}

spring-web/src/test/java/org/springframework/mock/web/test/MockHttpServletResponse.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -192,12 +192,10 @@ public PrintWriter getWriter() throws UnsupportedEncodingException {
192192
}
193193

194194
public byte[] getContentAsByteArray() {
195-
flushBuffer();
196195
return this.content.toByteArray();
197196
}
198197

199198
public String getContentAsString() throws UnsupportedEncodingException {
200-
flushBuffer();
201199
return (this.characterEncoding != null ?
202200
this.content.toString(this.characterEncoding) : this.content.toString());
203201
}

0 commit comments

Comments
 (0)