diff --git a/commands/http/handler.go b/commands/http/handler.go index 44646d31f774824bf8fd889579104e260925185f..270ad4ac06099d54fbba50b262876cf1365da540 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -288,6 +288,7 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req log.Error("err: ", err) w.Header().Set(StreamErrHeader, sanitizedErrStr(err)) } + } func flushCopy(w io.Writer, r io.Reader) error { @@ -298,6 +299,9 @@ func flushCopy(w io.Writer, r io.Reader) error { return err } for { + // flush to send header when r is not ready yet + f.Flush() + n, err := r.Read(buf) switch err { case io.EOF: @@ -320,8 +324,6 @@ func flushCopy(w io.Writer, r io.Reader) error { if nw != n { return fmt.Errorf("http write failed to write full amount: %d != %d", nw, n) } - - f.Flush() } return nil }