Closed eltishehu closed 4 months ago
Hi
I tested it with the demo app (Spring Boot 3.3.0 and sse-eventbus 2.0.1) just now and with this application it looks okay.
Can you upgrade the sse-eventbus library to 2.0.1 and try it without setting the contentType. This should not be necessary. Spring should set the correct content type.
// response.setContentType(MediaType.TEXT_EVENT_STREAM_VALUE);
Hello,
Thank you for replying.
I get the same result with sse-eventbus 2.0.1
and removing the explicit setting for content type.
I have debugged the issue and have tracked it down to this method: org.springframework.web.servlet.mvc.method.annotation.SseEmitter.SseEventBuilderImpl#saveAppendedText
This is Spring's class and it sets the event's type to text/plain:
But I checked the old version I was using and the code seems the same on Spring's side.
Not sure what has changed now.
Do you have any idea?
I've created an example project based on your code and it works fine. It always sends back the correct mime type text/event-stream.
https://github.com/ralscha/sse-spring-demo2
Could there be some other component/service in your system that handles the response and somehow changes the mime type.
I do have several filters in my application for handling the request/response, but none of them manipulates the content type. I have checked them all and nothing suspicious happen there to have anything to do with this issue. This used to work fine before upgrading to Spring Boot 3. I suspect it is a library compatibility issue.
Very mysterious. I've scrolled through the issues of the Spring framework, but there are no mentions of a similar problem: Spring Framework Issues
Apparently the issue was with the Spring Boot version. Upgrading from 3.2.3 to 3.3.0 solved the issue. 🤔
Interesting. Looking through the changelog of Spring Boot but can't find anything regarding server-sent events. https://github.com/spring-projects/spring-boot/releases
Glad to hear that it works now. Thanks for the feedback.
Thank you for taking the time to answer and looking into the issue. Appreciate it. Have a great one!
I am encountering an issue when using the SseEventBus library in my Spring Boot application to show a progress bar for an upload process. The error message I receive in the browser is:
EventSource's response has a MIME type ("text/plain") that is not "text/event-stream". Aborting the connection.
I have followed all the steps in the README file and this used to work perfectly fine before upgrading to Spring Boot 3.
Old versions: Spring Boot 2.3.5.RELEASE sse-eventbus 1.1.9
New versions: Spring Boot 3.2.3 sse-eventbus 2.0.0
I have added the
@EnableSseEventBus
annotation to my Spring application class.This is my controller method:
This is my DataEmitterService:
These are the methods on the client side:
This is the error on my browser:
If there are any configurations or specific methods in SseEventBus to ensure the correct MIME type is set, please let me know. Any guidance or fixes would be greatly appreciated.
Thank you for your assistance.