Deferred handling of Flux error in Spring MVC
This commit defers flushing of the response until the first item is emitted that needs to be written (and flushed) to the response. This makes Spring MVC consistent with WebFlux in this regard. Closes gh-21972
This commit is contained in:
@@ -152,9 +152,8 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
||||
// 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();
|
||||
// Wrap the response to ignore further header changes
|
||||
// Headers will be flushed at the first write
|
||||
outputMessage = new StreamingServletServerHttpResponse(outputMessage);
|
||||
|
||||
DeferredResult<?> deferredResult = new DeferredResult<>(emitter.getTimeout());
|
||||
@@ -198,7 +197,13 @@ public class ResponseBodyEmitterReturnValueHandler implements HandlerMethodRetur
|
||||
|
||||
@Override
|
||||
public void complete() {
|
||||
this.deferredResult.setResult(null);
|
||||
try {
|
||||
this.outputMessage.flush();
|
||||
this.deferredResult.setResult(null);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
this.deferredResult.setErrorResult(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user