Skip to content

Commit

Permalink
http api: makes sure header is sent even when r is not ready yet. fixes
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
keks authored and whyrusleeping committed Oct 18, 2016
1 parent 01ea333 commit 68d8a29
Showing 1 changed file with 4 additions and 2 deletions.
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()

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

3 comments on commit 68d8a29

@daviddias
Copy link
Member

@daviddias daviddias commented on 68d8a29 Oct 29, 2016

Choose a reason for hiding this comment

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

@whyrusleeping
Copy link
Member

Choose a reason for hiding this comment

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

@diasdavid Yeah... i'm seeing this now. Bizarre

@keks
Copy link
Contributor Author

@keks keks commented on 68d8a29 Nov 7, 2016

Choose a reason for hiding this comment

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

Can we just undo this? It will take a while to do this right and it would be nice if ipfs add worked from js until then :)
This tried to make go's pubsub better, and that is not really used atm anyway.

Please sign in to comment.