Closed mooijtech closed 2 years ago
It seems like for some reason the http.ResponseWriter has no http.Flusher?
As per the documentation:
The default HTTP/1.x and HTTP/2 ResponseWriter implementations
support Flusher, but ResponseWriter wrappers may not.
I am using a CORS wrapper:
corsHandler := cors.New(cors.Options{
AllowedOrigins: []string{"http://localhost:3000", "http://127.0.0.1:3000"},
AllowedMethods: []string{http.MethodGet, http.MethodPost, http.MethodDelete},
AllowCredentials: true,
}).Handler(server.Router)
Logger.Fatal(http.ListenAndServe(":1337", server.SessionManager.LoadAndSave(corsHandler)))
Most likely this is the issue.
I need CORS otherwise the EventSource request will be blocked by CORS.
I'm still getting "Streaming unsupported!" even if I add the CORS header manually and remove the CORS library.
Maybe the session manager doesn't support it?
Hey @mooijtech ,
Please could you try and run this simpler example and see if it behaves correctly? I am unable to reproduce the issue you are seeing.
package main
import (
"time"
"net/http"
"github.com/r3labs/sse/v2"
)
func main() {
s := sse.New()
s.CreateStream("test")
go func() {
for {
s.Publish("test", &sse.Event{Data: []byte("hello")})
time.Sleep(time.Second)
}
}()
s.Headers = map[string]string{
"Access-Control-Allow-Origin": "*",
}
// Create a new Mux and set the handler
mux := http.NewServeMux()
mux.HandleFunc("/", s.ServeHTTP)
http.ListenAndServe(":8080", mux)
}
Hello,
Thanks for your response. It seems to be an issue with the session manager I'm using. I have removed the server.SessionManager.LoadAndSave function and now it works. It seems the session manager is wrapping http.ResponseWriter and apparently doesn't have the http.Flusher.
I will open an issue there.
Hello,
I am trying to setup SSE for a progress bar but I am getting "Streaming unsupported!" in FireFox.
Client:
Server: