Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http api: makes sure header is sent even when r is not ready yet. fixes #3304 #3305

Merged
merged 4 commits into from
Oct 18, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions commands/http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably want to check and handle the error here, just in case

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flush doens't return an error, that's why the tests failed :D


n, err := r.Read(buf)
switch err {
case io.EOF:
Expand All @@ -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
}
Expand Down