Skip to content

Commit

Permalink
cleanup: create flusher at point of use
Browse files Browse the repository at this point in the history
  • Loading branch information
chetan committed Nov 3, 2021
1 parent 9fe73a6 commit d6e63b7
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,6 @@ func (d *Daemon) registerVhost(w http.ResponseWriter, r *http.Request) {
// streamLogs for a given hostname back to the caller. Runs forever until client
// disconnects.
func (d *Daemon) streamLogs(w http.ResponseWriter, r *http.Request) {
rw := w.(*LogRecord).ResponseWriter
flusher, ok := rw.(http.Flusher)
if !ok {
http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
return
}

hostname := r.PostFormValue("host")
logChan := d.loggedHandler.VhostLogListeners[hostname]
if logChan == nil {
Expand All @@ -212,10 +205,16 @@ func (d *Daemon) streamLogs(w http.ResponseWriter, r *http.Request) {
}

// runs forever until connection closes
d.relayLogsUntilClose(flusher, logChan, w, r.Context())
d.relayLogsUntilClose(logChan, w, r.Context())
}

func (d *Daemon) relayLogsUntilClose(flusher http.Flusher, logChan chan string, w http.ResponseWriter, reqCtx context.Context) {
func (d *Daemon) relayLogsUntilClose(logChan chan string, w http.ResponseWriter, reqCtx context.Context) {
flusher, ok := w.(*LogRecord).ResponseWriter.(http.Flusher)
if !ok {
http.Error(w, "Streaming unsupported!", http.StatusInternalServerError)
return
}

// Listen to connection close and un-register logChan
for {
select {
Expand Down

0 comments on commit d6e63b7

Please sign in to comment.