亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么在 go1.16 上為傳輸配置 ReadIdleTimeout HTTP/2 選項?

為什么在 go1.16 上為傳輸配置 ReadIdleTimeout HTTP/2 選項?

Go
當年話下 2022-10-10 15:29:21
從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 選項?
查看完整描述

1 回答

?
繁星點點滴滴

TA貢獻1803條經驗 獲得超3個贊

在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.


查看完整回答
反對 回復 2022-10-10
  • 1 回答
  • 0 關注
  • 119 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號