Skip to content
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
10 changes: 10 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ type lenReadSeeker interface {

type dummyReadCloser struct {
orig any // string or []byte
mu sync.Mutex // protects operations over body
body lenReadSeeker // instanciated on demand from orig
}

Expand All @@ -766,17 +767,26 @@ func (d *dummyReadCloser) setup() {
}

func (d *dummyReadCloser) Read(p []byte) (n int, err error) {
d.mu.Lock()
defer d.mu.Unlock()

d.setup()
return d.body.Read(p)
}

func (d *dummyReadCloser) Close() error {
d.mu.Lock()
defer d.mu.Unlock()

d.setup()
d.body.Seek(0, io.SeekEnd) //nolint: errcheck
return nil
}

func (d *dummyReadCloser) Len() int {
d.mu.Lock()
defer d.mu.Unlock()

d.setup()
return d.body.Len()
}