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>
keks committed
Oct 19, 2016 at 00:46 UTC
68d8a298c58ed950bd44118cc5e6d1ffc2def395
1 file changed
+4
-2
commands/http/handler.go
+4
-2
@@ -288,6 +288,7 @@ func sendResponse(w http.ResponseWriter, r *http.Request, res cmds.Response, req
288
log.Error("err: ", err)
289
w.Header().Set(StreamErrHeader, sanitizedErrStr(err))
290
}
291
+
292
}
293
294
func flushCopy(w io.Writer, r io.Reader) error {
@@ -298,6 +299,9 @@ func flushCopy(w io.Writer, r io.Reader) error {
299
return err
300
}
301
for {
302
+ // flush to send header when r is not ready yet
303
+ f.Flush()
304
+
305
n, err := r.Read(buf)
306
switch err {
307
case io.EOF:
@@ -320,8 +324,6 @@ func flushCopy(w io.Writer, r io.Reader) error {
324
if nw != n {
325
return fmt.Errorf("http write failed to write full amount: %d != %d", nw, n)
326
}
323
-
324
- f.Flush()
327
}
328
return nil
329
}