From 3a4f99314d2fc4a7701b8cd9908e91b3f1cdfca9 Mon Sep 17 00:00:00 2001 From: gohumble Date: Sun, 21 Aug 2022 00:02:48 +0200 Subject: [PATCH] sse --- internal/api/lightning.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/api/lightning.go b/internal/api/lightning.go index f1af669..6903c54 100644 --- a/internal/api/lightning.go +++ b/internal/api/lightning.go @@ -140,7 +140,9 @@ func (s Service) InvoiceStream(w http.ResponseWriter, r *http.Request) { return } w.Header().Set("Content-Type", "text/event-stream") - flusher.Flush() + w.Header().Set("Cache-Control", "no-cache") + w.Header().Set("Connection", "keep-alive") + client.Subscribe("", func(msg *sse.Event) { // Got some data! @@ -156,7 +158,7 @@ func (s Service) InvoiceStream(w http.ResponseWriter, r *http.Request) { } } if msg.Data != nil { - fmt.Fprintf(w, "%s", string(msg.Data)) + fmt.Fprintf(w, "data: %s\n", msg.Event) } flusher.Flush() })