Skip to content

Commit 7cc6f4c

Browse files
Fix DoTimeout Streaming body bug
1 parent 9a0b4d0 commit 7cc6f4c

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

http.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,14 @@ func swapRequestBody(a, b *Request) {
783783
a.body, b.body = b.body, a.body
784784
a.bodyRaw, b.bodyRaw = b.bodyRaw, a.bodyRaw
785785
a.bodyStream, b.bodyStream = b.bodyStream, a.bodyStream
786+
787+
// This code assumes that if a requestStream was swapped the headers are also swapped or copied.
788+
if rs, ok := a.bodyStream.(*requestStream); ok {
789+
rs.header = &a.Header
790+
}
791+
if rs, ok := b.bodyStream.(*requestStream); ok {
792+
rs.header = &b.Header
793+
}
786794
}
787795

788796
func swapResponseBody(a, b *Response) {
@@ -1881,6 +1889,9 @@ func (req *Request) closeBodyStream() error {
18811889
if bsc, ok := req.bodyStream.(io.Closer); ok {
18821890
err = bsc.Close()
18831891
}
1892+
if rs, ok := req.bodyStream.(*requestStream); ok {
1893+
releaseRequestStream(rs)
1894+
}
18841895
req.bodyStream = nil
18851896
return err
18861897
}

server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,7 @@ func (s *Server) serveConn(c net.Conn) (err error) {
24402440
if rs, ok := ctx.Request.bodyStream.(*requestStream); ok {
24412441
releaseRequestStream(rs)
24422442
}
2443+
ctx.Request.bodyStream = nil
24432444
}
24442445

24452446
s.setState(c, StateIdle)

streaming.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ func releaseRequestStream(rs *requestStream) {
9898
rs.totalBytesRead = 0
9999
rs.chunkLeft = 0
100100
rs.reader = nil
101+
rs.header = nil
101102
requestStreamPool.Put(rs)
102103
}
103104

0 commit comments

Comments
 (0)