Skip to content

Commit efc806e

Browse files
committed
net/http: clarify some RoundTripper behaviors
Fixes #12796 Updates #13444 Change-Id: I56840c0baf9b32a683086a80f5db1c5ea0a7aedf Reviewed-on: https://go-review.googlesource.com/17680 Reviewed-by: Russ Cox <[email protected]>
1 parent 7e1791b commit efc806e

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/net/http/client.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,19 +83,26 @@ var DefaultClient = &Client{}
8383
// goroutines.
8484
type RoundTripper interface {
8585
// RoundTrip executes a single HTTP transaction, returning
86-
// the Response for the request req. RoundTrip should not
87-
// attempt to interpret the response. In particular,
88-
// RoundTrip must return err == nil if it obtained a response,
89-
// regardless of the response's HTTP status code. A non-nil
90-
// err should be reserved for failure to obtain a response.
91-
// Similarly, RoundTrip should not attempt to handle
92-
// higher-level protocol details such as redirects,
86+
// a Response for the provided Request.
87+
//
88+
// RoundTrip should not attempt to interpret the response. In
89+
// particular, RoundTrip must return err == nil if it obtained
90+
// a response, regardless of the response's HTTP status code.
91+
// A non-nil err should be reserved for failure to obtain a
92+
// response. Similarly, RoundTrip should not attempt to
93+
// handle higher-level protocol details such as redirects,
9394
// authentication, or cookies.
9495
//
9596
// RoundTrip should not modify the request, except for
96-
// consuming and closing the Body, including on errors. The
97-
// request's URL and Header fields are guaranteed to be
98-
// initialized.
97+
// consuming and closing the Request's Body.
98+
//
99+
// RoundTrip must always close the body, including on errors,
100+
// but depending on the implementation may do so in a separate
101+
// goroutine even after RoundTrip returns. This means that
102+
// callers wanting to reuse the body for subsequent requests
103+
// must arrange to wait for the Close call before doing so.
104+
//
105+
// The Request's URL and Header fields must be initialized.
99106
RoundTrip(*Request) (*Response, error)
100107
}
101108

0 commit comments

Comments
 (0)