Skip to content

Commit

Permalink
Don't touch the buf
Browse files Browse the repository at this point in the history
  • Loading branch information
emcfarlane committed Oct 30, 2023
1 parent 5948976 commit 204d37d
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions http_call.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ func (c *httpCall) sendUnary(buffer *bytes.Buffer) error {
c.request.Body = payload
c.request.ContentLength = int64(buffer.Len())
c.request.GetBody = func() (io.ReadCloser, error) {
if !payload.Rewind() {
return nil, errors.New("payload already sent")
}
payload.Rewind()
return payload, nil
}
// Wait for the payload to be fully drained before we return
Expand Down Expand Up @@ -366,21 +364,16 @@ func (p *payloadCloser) Close() error {
// has been discarded.
// Note: it should not be possible for GetBody to be called after the response
// is received.
func (p *payloadCloser) Rewind() bool {
if p.buf == nil {
return false
}
func (p *payloadCloser) Rewind() {
p.readN = 0
if p.isDone.CompareAndSwap(true, false) {
p.wait.Add(1)
}
return true
}

// Wait blocks until the payload has been fully read.
func (p *payloadCloser) Wait() {
p.wait.Wait()
p.buf = nil // release the buffer
}

// complete signals that the payload has been fully read.
Expand Down

0 comments on commit 204d37d

Please sign in to comment.