diff options
author | Valentin Rothberg <rothberg@redhat.com> | 2020-09-15 14:28:38 +0200 |
---|---|---|
committer | Valentin Rothberg <rothberg@redhat.com> | 2020-09-15 14:28:38 +0200 |
commit | 0b7cb2c6b2c435a6301740675382b2e55d0588be (patch) | |
tree | 3107aad4c8e41c43654ee419a4e0bce3882f5934 /pkg/api/handlers/compat/events.go | |
parent | 5c47a331ba768d57ef94b9595415500f4e911964 (diff) | |
download | podman-0b7cb2c6b2c435a6301740675382b2e55d0588be.tar.gz podman-0b7cb2c6b2c435a6301740675382b2e55d0588be.tar.bz2 podman-0b7cb2c6b2c435a6301740675382b2e55d0588be.zip |
events endpoint: header: do not wait for events
Do not wait for events to occur before writing the OK header.
Events can take an unknown amount of time to occur and clients
do not need to wait until then to know if the connection is
good.
Fixes: #7263
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'pkg/api/handlers/compat/events.go')
-rw-r--r-- | pkg/api/handlers/compat/events.go | 22 |
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 } |