从google api golang 客户端,我们注意到
google-api-go-client/transport/http/configure_http2_go116.go
//go:build go1.16
// +build go1.16
...
// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the
// transport. This allows broken idle connections to be pruned more quickly,
// preventing the client from attempting to re-use connections that will no
// longer work.
func configureHTTP2(trans *http.Transport) {
http2Trans, err := http2.ConfigureTransports(trans)
if err == nil {
http2Trans.ReadIdleTimeout = time.Second * 31
}
}
而在这个文件中google-api-go-client/transport/http/configure_http2_not_go116.go
//go:build !go1.16
// +build !go1.16
// configureHTTP2 configures the ReadIdleTimeout HTTP/2 option for the
// transport. The interface to do this is only available in Go 1.16 and up, so
// this performs a no-op.
func configureHTTP2(trans *http.Transport) {}
Pernet/http2/transport.go是ConfigureTransport很久以前添加的。
// ConfigureTransport configures a net/http HTTP/1 Transport to use HTTP/2.
// It returns an error if t1 has already been HTTP/2-enabled.
//
// Use ConfigureTransports instead to configure the HTTP/2 Transport.
func ConfigureTransport(t1 *http.Transport) error {
为什么在 go1.16 上为传输配置 ReadIdleTimeout HTTP/2 选项?
繁星点点滴滴
相关分类