Skip to content

Commit 314d58a

Browse files
DavyJohnesmaxatome
authored andcommitted
fix: protect all body-related methods with mutext
1 parent e482896 commit 314d58a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

response.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ type lenReadSeeker interface {
740740

741741
type dummyReadCloser struct {
742742
orig any // string or []byte
743+
mu sync.Mutex // protects operations over body
743744
body lenReadSeeker // instanciated on demand from orig
744-
mu sync.Mutex
745745
}
746746

747747
// copy returns a new instance resetting d.body to nil.
@@ -767,6 +767,9 @@ func (d *dummyReadCloser) setup() {
767767
}
768768

769769
func (d *dummyReadCloser) Read(p []byte) (n int, err error) {
770+
d.mu.Lock()
771+
defer d.mu.Unlock()
772+
770773
d.setup()
771774
return d.body.Read(p)
772775
}
@@ -781,6 +784,9 @@ func (d *dummyReadCloser) Close() error {
781784
}
782785

783786
func (d *dummyReadCloser) Len() int {
787+
d.mu.Lock()
788+
defer d.mu.Unlock()
789+
784790
d.setup()
785791
return d.body.Len()
786792
}

0 commit comments

Comments
 (0)