diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java
index e078a66d110a..ffc74fde6369 100644
--- a/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java
+++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/function/SseServerResponse.java
@@ -48,6 +48,7 @@
* Server-Sent Events.
*
* @author Arjen Poutsma
+ * @author Sebastien Deleuze
* @since 5.3.2
*/
final class SseServerResponse extends AbstractServerResponse {
@@ -90,7 +91,7 @@ protected ModelAndView writeToInternal(HttpServletRequest request, HttpServletRe
}
DefaultAsyncServerResponse.writeAsync(request, response, result);
- this.sseConsumer.accept(new DefaultSseBuilder(response, context, result));
+ this.sseConsumer.accept(new DefaultSseBuilder(response, context, result, this.headers()));
return null;
}
@@ -113,15 +114,19 @@ private static final class DefaultSseBuilder implements SseBuilder {
private final List> messageConverters;
+ private final HttpHeaders httpHeaders;
+
private final StringBuilder builder = new StringBuilder();
private boolean sendFailed;
- public DefaultSseBuilder(HttpServletResponse response, Context context, DeferredResult> deferredResult) {
+ public DefaultSseBuilder(HttpServletResponse response, Context context, DeferredResult> deferredResult,
+ HttpHeaders httpHeaders) {
this.outputMessage = new ServletServerHttpResponse(response);
this.deferredResult = deferredResult;
this.messageConverters = context.messageConverters();
+ this.httpHeaders = httpHeaders;
}
@Override
@@ -206,7 +211,7 @@ private void writeObject(Object data) throws IOException {
for (HttpMessageConverter> converter : this.messageConverters) {
if (converter.canWrite(dataClass, MediaType.APPLICATION_JSON)) {
HttpMessageConverter