From 68d8a298c58ed950bd44118cc5e6d1ffc2def395 Mon Sep 17 00:00:00 2001
From: keks <j-winkelmann@tuhh.de>
Date: Wed, 19 Oct 2016 00:46:07 +0200
Subject: [PATCH] http api: makes sure header is sent even when r is not ready
 yet. fixes #3304 (#3305)

* http api: send header even when r is not ready yet. fixes #3304

License: MIT
Signed-off-by: Jan Winkelmann <j-winkelmann@tuhh.de>

* http api: check flush error and only flush once per iteration

License: MIT
Signed-off-by: Jan Winkelmann <j-winkelmann@tuhh.de>

* http api: f.Flush is not in fact returning anything

License: MIT
Signed-off-by: Jan Winkelmann <j-winkelmann@tuhh.de>

* api http: remove pointless Flush

License: MIT
Signed-off-by: Jan Winkelmann <j-winkelmann@tuhh.de>
---
 commands/http/handler.go | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/commands/http/handler.go b/commands/http/handler.go
index 44646d31f..270ad4ac0 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
 }
-- 
GitLab