mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Merge branch '7.0.x'
This commit is contained in:
+2
-4
@@ -17,7 +17,6 @@
|
||||
package org.springframework.web.servlet.function;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Duration;
|
||||
import java.util.Collections;
|
||||
@@ -137,9 +136,8 @@ final class SseServerResponse extends AbstractServerResponse {
|
||||
public void send() throws IOException {
|
||||
this.builder.append('\n');
|
||||
try {
|
||||
OutputStream body = this.outputMessage.getBody();
|
||||
body.write(builderBytes());
|
||||
body.flush();
|
||||
this.outputMessage.getBody().write(builderBytes());
|
||||
this.outputMessage.flush();
|
||||
}
|
||||
catch (IOException ex) {
|
||||
this.sendFailed = true;
|
||||
|
||||
+35
@@ -75,6 +75,41 @@ class SseServerResponseTests {
|
||||
assertThat(this.mockResponse.getContentAsString()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test // gh-36537
|
||||
void sendStringFlushesResponse() throws Exception {
|
||||
ServerResponse response = ServerResponse.sse(sse -> {
|
||||
try {
|
||||
sse.send("foo bar");
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
ServerResponse.Context context = Collections::emptyList;
|
||||
|
||||
response.writeTo(this.mockRequest, this.mockResponse, context);
|
||||
assertThat(this.mockResponse.isCommitted()).isTrue();
|
||||
}
|
||||
|
||||
@Test // gh-36537
|
||||
void sendObjectFlushesResponse() throws Exception {
|
||||
Person person = new Person("John Doe", 42);
|
||||
ServerResponse response = ServerResponse.sse(sse -> {
|
||||
try {
|
||||
sse.send(person);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
});
|
||||
|
||||
ServerResponse.Context context = () -> List.of(new JacksonJsonHttpMessageConverter());
|
||||
|
||||
response.writeTo(this.mockRequest, this.mockResponse, context);
|
||||
assertThat(this.mockResponse.isCommitted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void sendObject() throws Exception {
|
||||
Person person = new Person("John Doe", 42);
|
||||
|
||||
Reference in New Issue
Block a user