@@ -152,19 +152,47 @@ func (t *Transport) pingTimeout() time.Duration {
152
152
153
153
}
154
154
155
+ // TransportOptions contains options to configure HTTP/2 transport.
156
+ type TransportOptions struct {
157
+ // ReadIdleTimeout is the timeout after which a health check using ping
158
+ // frame will be carried out if no frame is received on the connection.
159
+ // Note that a ping response will is considered a received frame, so if
160
+ // there is no other traffic on the connection, the health check will
161
+ // be performed every ReadIdleTimeout interval.
162
+ // If zero, no health check is performed.
163
+ ReadIdleTimeout time.Duration
164
+
165
+ // PingTimeout is the timeout after which the connection will be closed
166
+ // if a response to Ping is not received.
167
+ // Defaults to 15s.
168
+ PingTimeout time.Duration
169
+ }
170
+
171
+ // ConfigureTransport configures a net/http HTTP/1 Transport to use HTTP/2.
172
+ // The options can be used to configure the HTTP/2 Transport.
173
+ // It returns an error if t1 has already been HTTP/2-enabled.
174
+ func ConfigureTransportWithOptions (t1 * http.Transport , o * TransportOptions ) error {
175
+ _ , err := configureTransport (t1 , o )
176
+ return err
177
+ }
178
+
155
179
// ConfigureTransport configures a net/http HTTP/1 Transport to use HTTP/2.
156
180
// It returns an error if t1 has already been HTTP/2-enabled.
157
181
func ConfigureTransport (t1 * http.Transport ) error {
158
- _ , err := configureTransport (t1 )
182
+ _ , err := configureTransport (t1 , nil )
159
183
return err
160
184
}
161
185
162
- func configureTransport (t1 * http.Transport ) (* Transport , error ) {
186
+ func configureTransport (t1 * http.Transport , o * TransportOptions ) (* Transport , error ) {
163
187
connPool := new (clientConnPool )
164
188
t2 := & Transport {
165
189
ConnPool : noDialClientConnPool {connPool },
166
190
t1 : t1 ,
167
191
}
192
+ if o != nil {
193
+ t2 .ReadIdleTimeout = o .ReadIdleTimeout
194
+ t2 .PingTimeout = o .PingTimeout
195
+ }
168
196
connPool .t = t2
169
197
if err := registerHTTPSProtocol (t1 , noDialH2RoundTripper {t2 }); err != nil {
170
198
return nil , err
0 commit comments