Skip to content

Remove UTF-8 charset parameter from Content-Type in SseEmitter #24632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -70,7 +67,7 @@ protected void extendResponse(ServerHttpResponse outputMessage) {

HttpHeaders headers = outputMessage.getHeaders();
if (headers.getContentType() == null) {
headers.setContentType(TEXT_EVENTSTREAM);
headers.setContentType(MediaType.TEXT_EVENT_STREAM);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void sseEmitter() throws Exception {
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" +
Expand All @@ -238,7 +238,7 @@ public void responseBodyFlux() throws Exception {
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");
}

Expand Down Expand Up @@ -272,7 +272,7 @@ public void responseEntitySse() throws Exception {

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");
}

Expand Down