MockMvc re-uses response instance on async dispatch

MockMvc now properly detects the presence of an AsyncContext and
re-uses the response instance used to start it.

This commit also includes a minor fix in
ResponseBodyEmitterReturnValueHandler to ensure it does not disable
ETag related content buffering for reactive return values that do not
result in streaming (e.g. single value or collections).

Issue: SPR-16067
This commit is contained in:
Rossen Stoyanchev
2017-10-17 16:57:35 -04:00
parent 94c4a7f941
commit cd634633d8
3 changed files with 91 additions and 32 deletions

View File

@@ -140,23 +140,23 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
ServletRequest request = webRequest.getNativeRequest(ServletRequest.class);
Assert.state(request != null, "No ServletRequest");
ShallowEtagHeaderFilter.disableContentCaching(request);
ResponseBodyEmitter emitter;
if (returnValue instanceof ResponseBodyEmitter) {
emitter = (ResponseBodyEmitter) returnValue;
}
else {
emitter = this.reactiveHandler.handleValue(returnValue, returnType, mavContainer, webRequest);
if (emitter == null) {
// Not streaming..
return;
}
}
if (emitter == null) {
return;
}
emitter.extendResponse(outputMessage);
// At this point we know we're streaming..
ShallowEtagHeaderFilter.disableContentCaching(request);
// Commit the response and wrap to ignore further header changes
outputMessage.getBody();
outputMessage.flush();