Write headers manually for streaming response writers before calling Flush()
Signed-off-by: Christopher Petito <47751006+krissetto@users.noreply.github.com>
This commit is contained in:
parent
8d5d655db0
commit
8224204c9f
2 changed files with 14 additions and 1 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
|
||||
|
@ -17,9 +18,14 @@ import (
|
|||
// WriteLogStream writes an encoded byte stream of log messages from the
|
||||
// messages channel, multiplexing them with a stdcopy.Writer if mux is true
|
||||
func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *container.LogsOptions, mux bool) {
|
||||
// Used before the Flush(), so we don't set the header twice because of the otel wrapper
|
||||
// see here: https://github.com/moby/moby/issues/47448
|
||||
if rw, ok := w.(http.ResponseWriter); ok {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
wf := ioutils.NewWriteFlusher(w)
|
||||
defer wf.Close()
|
||||
|
||||
wf.Flush()
|
||||
|
||||
outStream := io.Writer(wf)
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"net/http"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
|
@ -46,6 +47,12 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
|
|||
|
||||
outStream := config.OutStream
|
||||
if config.Stream {
|
||||
// Used before the Flush(), so we don't set the header twice because of the otel wrapper
|
||||
// see here: https://github.com/moby/moby/issues/47448
|
||||
if rw, ok := outStream.(http.ResponseWriter); ok {
|
||||
rw.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
wf := ioutils.NewWriteFlusher(outStream)
|
||||
defer wf.Close()
|
||||
wf.Flush()
|
||||
|
|
Loading…
Reference in a new issue