summaryrefslogtreecommitdiff
path: root/pkg/api/handlers/compat
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-09-15 17:19:45 +0200
committerGitHub <noreply@github.com>2020-09-15 17:19:45 +0200
commit0be5836e49da38b156951639b7e19eaec6a6e593 (patch)
tree4045bc3fc1dd2595662f2eba35a7365f0aaa09a2 /pkg/api/handlers/compat
parent3f6045ce20f02257bcab7a51bcd884a5321ca7db (diff)
parent0b7cb2c6b2c435a6301740675382b2e55d0588be (diff)
downloadpodman-0be5836e49da38b156951639b7e19eaec6a6e593.tar.gz
podman-0be5836e49da38b156951639b7e19eaec6a6e593.tar.bz2
podman-0be5836e49da38b156951639b7e19eaec6a6e593.zip
Merge pull request #7637 from vrothberg/fix-7263
events endpoint: header: do not wait for events
Diffstat (limited to 'pkg/api/handlers/compat')
-rw-r--r--pkg/api/handlers/compat/events.go22
1 files changed, 7 insertions, 15 deletions
diff --git a/pkg/api/handlers/compat/events.go b/pkg/api/handlers/compat/events.go
index 289bf4a2d..fbb33410f 100644
--- a/pkg/api/handlers/compat/events.go
+++ b/pkg/api/handlers/compat/events.go
@@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"net/http"
- "sync"
"github.com/containers/podman/v2/libpod"
"github.com/containers/podman/v2/libpod/events"
@@ -113,8 +112,13 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
errorChannel <- runtime.Events(r.Context(), readOpts)
}()
- var coder *jsoniter.Encoder
- var writeHeader sync.Once
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(http.StatusOK)
+ if flusher, ok := w.(http.Flusher); ok {
+ flusher.Flush()
+ }
+ coder := json.NewEncoder(w)
+ coder.SetEscapeHTML(true)
for stream := true; stream; stream = query.Stream {
select {
@@ -124,18 +128,6 @@ func GetEvents(w http.ResponseWriter, r *http.Request) {
return
}
case evt := <-eventChannel:
- writeHeader.Do(func() {
- // Use a sync.Once so that we write the header
- // only once.
- w.Header().Set("Content-Type", "application/json")
- w.WriteHeader(http.StatusOK)
- if flusher, ok := w.(http.Flusher); ok {
- flusher.Flush()
- }
- coder = json.NewEncoder(w)
- coder.SetEscapeHTML(true)
- })
-
if evt == nil {
continue
}