Skip to content

Commit d97e3d5

Browse files
Allow resending the request body
Sometimes (especially with HTTP 2 connections) the body needs to be sent again. Always set GetBody() so that this is possible.
1 parent 47e882b commit d97e3d5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

request/request.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,9 @@ func requestFromBuffer(buf []byte, target *url.URL, replace func([]byte) []byte)
277277

278278
origBody = append(origBody, rest...)
279279
req.Body = io.NopCloser(bytes.NewReader(origBody))
280+
req.GetBody = func() (io.ReadCloser, error) {
281+
return io.NopCloser(bytes.NewReader(origBody)), nil
282+
}
280283
req.ContentLength = int64(len(origBody))
281284

282285
// fill some details from the URL
@@ -375,6 +378,10 @@ func (r *Request) Apply(values []string) (*http.Request, error) {
375378
if len(body) > 0 {
376379
// use new body and set content length
377380
req.Body = io.NopCloser(bytes.NewReader(body))
381+
req.GetBody = func() (io.ReadCloser, error) {
382+
return io.NopCloser(bytes.NewReader(body)), nil
383+
}
384+
378385
req.ContentLength = int64(len(body))
379386
}
380387

0 commit comments

Comments
 (0)