为什么要为 go1.16 上的传输配置 ReadIdleTimeout HTTP/2 选项?
Why configures the ReadIdleTimeout HTTP/2 option for the transport on go1.16?
从google api golang client,我们注意到
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) {}
根据 net/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 选项?
包 golang.org/x/net/http2 中有两个相似的发音函数,但作用截然不同:
func ConfigureTransport (t1 *http.Transport) error
func ConfigureTransports (t1 *http.Transport) (*Transport, error)
我认为你混淆了前者和后者。
来自问题跟踪器:
https://go-review.googlesource.com/c/net/+/264017
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.
ConfigureTransports
整整一年前才推出:
commit 08b38378de702b893ee869b94b32f833e2933bd2
Author: Damien Neil <dneil@google.com>
Date: Tue Oct 20 12:34:04 2020 -0700
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.
从google api golang client,我们注意到
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) {}
根据 net/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 选项?
包 golang.org/x/net/http2 中有两个相似的发音函数,但作用截然不同:
func ConfigureTransport (t1 *http.Transport) error
func ConfigureTransports (t1 *http.Transport) (*Transport, error)
我认为你混淆了前者和后者。
来自问题跟踪器: https://go-review.googlesource.com/c/net/+/264017
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.
ConfigureTransports
整整一年前才推出:
commit 08b38378de702b893ee869b94b32f833e2933bd2
Author: Damien Neil <dneil@google.com>
Date: Tue Oct 20 12:34:04 2020 -0700
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.