從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) {}
每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 選項?
uj5u.com熱心網友回復:
在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
非常相似的名稱是不幸的,但它們將在 godoc 中彼此相鄰排序,復數的 ConfigureTransports 暗示其目的:它允許您配置 http 和 http2 傳輸。
ConfigureTransports 僅在一年前推出:
commit 08b38378de702b893ee869b94b32f833e2933bd2
Author: Damien Neil <[email protected]>
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.
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/334906.html
