From 35d5f94fd5e7cfe18105235f54f89bd8aa8af124 Mon Sep 17 00:00:00 2001 From: Kioubit Date: Thu, 18 Jul 2024 00:46:29 +0300 Subject: [PATCH] Ensure client has been added before starting the streamServer --- http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/http.go b/http.go index e8968e7..d950b81 100644 --- a/http.go +++ b/http.go @@ -174,7 +174,6 @@ func stream(w http.ResponseWriter, r *http.Request) { http.Error(w, "Streaming unsupported!", http.StatusInternalServerError) return } - streamServer() w.Header().Set("Content-Type", "text/event-stream") w.Header().Set("Cache-Control", "no-cache") w.Header().Set("Connection", "keep-alive") @@ -186,8 +185,9 @@ func stream(w http.ResponseWriter, r *http.Request) { clientMutex.Lock() clients = append(clients, newClient) clientMutex.Unlock() + streamServer() - // For when clients are removed prior to connection closed, to avoid a call to delete(clients, id) + // For when clients are removed prior to connection close, to avoid a call to deleteClient() var channelClosedFirst = false go func() { // Listen for connection close