How do I set MaxConnsPerHost on http2 transport in GoLang

huangapple go评论102阅读模式
英文:

How do I set MaxConnsPerHost on http2 transport in GoLang

问题

我正在尝试强制GoLang使用HTTP2,并进行了以下操作:

transport := &http2.Transport{}
client := &http.Client{Transport: transport}

但我还需要设置MaxConnsPerHost和MaxIdleConns,但我无法设置它们。我知道在HTTP1中可以按以下方式设置它们:

transport := &http.Transport{
	MaxIdleConns:        0,
	MaxIdleConnsPerHost: 1000,
}
httpClient := &http.Client{Transport: transport}

我该如何在HTTP2中实现相同的效果?

英文:

I'm trying to force GoLang to use HTTP2 and so have done the following:

transport := &http2.Transport{}
client := &http.Client{Transport: transport}

But I also need to set MaxConnsPerHost and MaxIdleConns, which I'm not able to. I know I can set them in HTTP1 as follows:

transport := &http.Transport{
	MaxIdleConns: 0,
	MaxIdleConnsPerHost: 1000,
}
httpClient := &http.Client{Transport: transport}

How can I achieve the same for HTTP2?

答案1

得分: 0

回答我自己的问题:正如Peter指出的那样,这不适用于HTTP2。

英文:

Answering my own question here: As Peter pointed out, this would not apply to HTTP2.

huangapple
  • 本文由 发表于 2021年6月1日 04:12:59
  • 转载请务必保留本文链接:https://go.coder-hub.com/67779729.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定