Remove charset from content-type in SseEmitter

See gh-24632
This commit is contained in:
sada-sigsci 2020-03-02 17:35:00 -08:00 committed by Rossen Stoyanchev
parent b2fe494b9c
commit cc1f57823b
2 changed files with 4 additions and 7 deletions

View File

@ -41,9 +41,6 @@ public class SseEmitter extends ResponseBodyEmitter {
static final MediaType TEXT_PLAIN = new MediaType("text", "plain", StandardCharsets.UTF_8);
static final MediaType TEXT_EVENTSTREAM = new MediaType("text", "event-stream", StandardCharsets.UTF_8);
/**
* Create a new SseEmitter instance.
*/
@ -70,7 +67,7 @@ public class SseEmitter extends ResponseBodyEmitter {
HttpHeaders headers = outputMessage.getHeaders();
if (headers.getContentType() == null) {
headers.setContentType(TEXT_EVENTSTREAM);
headers.setContentType(MediaType.TEXT_EVENT_STREAM);
}
}

View File

@ -211,7 +211,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
emitter.send(SseEmitter.event().
comment("a test").name("update").id("1").reconnectTime(5000L).data(bean1).data(bean2));
assertThat(this.response.getContentType()).isEqualTo("text/event-stream;charset=UTF-8");
assertThat(this.response.getContentType()).isEqualTo("text/event-stream");
assertThat(this.response.getContentAsString()).isEqualTo((":a test\n" +
"event:update\n" +
"id:1\n" +
@ -238,7 +238,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
processor.onNext("baz");
processor.onComplete();
assertThat(this.response.getContentType()).isEqualTo("text/event-stream;charset=UTF-8");
assertThat(this.response.getContentType()).isEqualTo("text/event-stream");
assertThat(this.response.getContentAsString()).isEqualTo("data:foo\n\ndata:bar\n\ndata:baz\n\n");
}
@ -272,7 +272,7 @@ public class ResponseBodyEmitterReturnValueHandlerTests {
assertThat(this.request.isAsyncStarted()).isTrue();
assertThat(this.response.getStatus()).isEqualTo(200);
assertThat(this.response.getContentType()).isEqualTo("text/event-stream;charset=UTF-8");
assertThat(this.response.getContentType()).isEqualTo("text/event-stream");
assertThat(this.response.getHeader("foo")).isEqualTo("bar");
}