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"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
@ -17,9 +18,14 @@ import (
|
||||||
// WriteLogStream writes an encoded byte stream of log messages from the
|
// WriteLogStream writes an encoded byte stream of log messages from the
|
||||||
// messages channel, multiplexing them with a stdcopy.Writer if mux is true
|
// 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) {
|
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)
|
wf := ioutils.NewWriteFlusher(w)
|
||||||
defer wf.Close()
|
defer wf.Close()
|
||||||
|
|
||||||
wf.Flush()
|
wf.Flush()
|
||||||
|
|
||||||
outStream := io.Writer(wf)
|
outStream := io.Writer(wf)
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
|
"net/http"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -46,6 +47,12 @@ func (daemon *Daemon) ContainerStats(ctx context.Context, prefixOrName string, c
|
||||||
|
|
||||||
outStream := config.OutStream
|
outStream := config.OutStream
|
||||||
if config.Stream {
|
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)
|
wf := ioutils.NewWriteFlusher(outStream)
|
||||||
defer wf.Close()
|
defer wf.Close()
|
||||||
wf.Flush()
|
wf.Flush()
|
||||||
|
|
Loading…
Reference in a new issue