From 95f548748ed486a69dab8641f61e6750458cd680 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 19 Apr 2020 16:25:24 -0300 Subject: [PATCH] allow Streamer to have custom extra headers. --- sse.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sse.go b/sse.go index 8b0178a..f116c8f 100644 --- a/sse.go +++ b/sse.go @@ -27,6 +27,8 @@ type Streamer struct { connecting chan client disconnecting chan client bufSize uint + + ExtraHeaders http.Header } // New returns a new initialized SSE Streamer @@ -37,6 +39,7 @@ func New() *Streamer { connecting: make(chan client), disconnecting: make(chan client), bufSize: 2, + ExtraHeaders: make(http.Header), } s.run() @@ -242,6 +245,9 @@ func (s *Streamer) ServeHTTP(w http.ResponseWriter, r *http.Request) { h.Set("Cache-Control", "no-cache") h.Set("Connection", "keep-alive") h.Set("Content-Type", "text/event-stream") + for k, v := range s.ExtraHeaders { + h[k] = v + } // Connect new client cl := make(client, s.bufSize)