Skip to content

Commit 08b3837

Browse files
committed
http2: add ConfigureTransports
The ConfigureTransport function doesn't provide any way to get at the http2 Transport it creates, making it impossible to configure transport parameters such as ReadIdleTimeout. Add a ConfigureTransports function which returns the http2 Transport. The very similar names are unfortunate, but they'll sort next to each other in godoc and the pluralized ConfigureTransports hints at its purpose: it lets you configure both the http and http2 transports. Fixes golang/go#40201. Updates golang/go#41721. Change-Id: I97aa345f369f49462c41d3f60d35660c06c51287 Reviewed-on: https://go-review.googlesource.com/c/net/+/264017 Trust: Damien Neil <[email protected]> Trust: Brad Fitzpatrick <[email protected]> Run-TryBot: Damien Neil <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent f585440 commit 08b3837

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

http2/transport.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,21 @@ func (t *Transport) pingTimeout() time.Duration {
154154

155155
// ConfigureTransport configures a net/http HTTP/1 Transport to use HTTP/2.
156156
// It returns an error if t1 has already been HTTP/2-enabled.
157+
//
158+
// Use ConfigureTransports instead to configure the HTTP/2 Transport.
157159
func ConfigureTransport(t1 *http.Transport) error {
158-
_, err := configureTransport(t1)
160+
_, err := ConfigureTransports(t1)
159161
return err
160162
}
161163

162-
func configureTransport(t1 *http.Transport) (*Transport, error) {
164+
// ConfigureTransports configures a net/http HTTP/1 Transport to use HTTP/2.
165+
// It returns a new HTTP/2 Transport for further configuration.
166+
// It returns an error if t1 has already been HTTP/2-enabled.
167+
func ConfigureTransports(t1 *http.Transport) (*Transport, error) {
168+
return configureTransports(t1)
169+
}
170+
171+
func configureTransports(t1 *http.Transport) (*Transport, error) {
163172
connPool := new(clientConnPool)
164173
t2 := &Transport{
165174
ConnPool: noDialClientConnPool{connPool},

0 commit comments

Comments
 (0)