Skip to content

Commit 3039bff

Browse files
committed
net/http: clarify when it is safe to reuse a request
The godoc for RoundTrip already specifies when it's ok to reuse a request that contains a body: the caller must wait until RoundTrip calls Close on Request.Body. This CL adds a small clarification: If the request does not have a body, it can be reused as long as the caller does not mutate the Request until RoundTrip fails or the Response.Body is closed. Fixes #19653 Change-Id: I56652a9369978d11650e2e6314104831c2ce5e78 Reviewed-on: https://go-review.googlesource.com/75671 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent af37332 commit 3039bff

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/net/http/client.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ type RoundTripper interface {
127127
// authentication, or cookies.
128128
//
129129
// RoundTrip should not modify the request, except for
130-
// consuming and closing the Request's Body.
130+
// consuming and closing the Request's Body. RoundTrip may
131+
// read fields of the request in a separate goroutine. Callers
132+
// should not mutate the request until the Response's Body has
133+
// been closed.
131134
//
132135
// RoundTrip must always close the body, including on errors,
133136
// but depending on the implementation may do so in a separate

0 commit comments

Comments
 (0)