Adding TODO and additional notes in README to correct mdn documentation

main
Drew Bednar 6 days ago
parent a3265bf763
commit c6e64b8160

@ -1,6 +1,6 @@
# learning_sse # learning_sse
Learning Server Side Events. Learning [Server Side Events](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events) can be fun.
The magic is in setting the `Content Type` header to `text/event-stream`, writing the response in the from of `data: %s \n\n`, and flushing the content of the WriteResponse buffer manually. This is necessary because by default Go will implicitly flush the buffer only once the Handler has returned. The magic is in setting the `Content Type` header to `text/event-stream`, writing the response in the from of `data: %s \n\n`, and flushing the content of the WriteResponse buffer manually. This is necessary because by default Go will implicitly flush the buffer only once the Handler has returned.

@ -23,6 +23,7 @@ func SSEHandler(w http.ResponseWriter, r *http.Request) {
} }
func routes() http.Handler { func routes() http.Handler {
// TODO add static server and an HTML index with `new EventSource` JS that writes the data message contents into an element on the page
mux := http.NewServeMux() mux := http.NewServeMux()
mux.HandleFunc("/sse", SSEHandler) mux.HandleFunc("/sse", SSEHandler)
return mux return mux

Loading…
Cancel
Save