Skip to content

Commit f20f6c9

Browse files
committed
Flush headers after null ResponseBodyEmitter
Issue: SPR-14315
1 parent 431a508 commit f20f6c9

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ public void handleReturnValue(Object returnValue, MethodParameter returnType,
137137
returnValue = responseEntity.getBody();
138138
if (returnValue == null) {
139139
mavContainer.setRequestHandled(true);
140+
outputMessage.flush();
140141
return;
141142
}
142143
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ResponseBodyEmitterReturnValueHandlerTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import java.lang.reflect.Method;
2323
import java.util.Arrays;
24+
import java.util.Collections;
2425
import java.util.List;
2526
import java.util.concurrent.atomic.AtomicReference;
2627

@@ -184,11 +185,12 @@ public void responseEntitySse() throws Exception {
184185
@Test
185186
public void responseEntitySseNoContent() throws Exception {
186187
MethodParameter returnType = returnType("handleResponseEntitySse");
187-
ResponseEntity<?> entity = ResponseEntity.noContent().build();
188+
ResponseEntity<?> entity = ResponseEntity.noContent().header("foo", "bar").build();
188189
handleReturnValue(entity, returnType);
189190

190191
assertFalse(this.request.isAsyncStarted());
191192
assertEquals(204, this.response.getStatus());
193+
assertEquals(Collections.singletonList("bar"), this.response.getHeaders("foo"));
192194
}
193195

194196
private void handleReturnValue(Object returnValue, MethodParameter returnType) throws Exception {

0 commit comments

Comments
 (0)