可以使用HTTP/2发出仅使用HTTP/2的HTTP请求。

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

Can I make an HTTP request that only uses HTTP/2

问题

我正在编写一些脚本来测试我们的基础设施在不同层面上的功能。我试图创建一些测试来验证客户端在有或没有使用http2的情况下的功能。文档中指定了如何通过覆盖Transport.TLSNextProto禁用http2,但我找不到任何方法来要求使用http2。

有没有一种方法可以要求一个http请求只使用http/2?如果没有,是否有任何字段或钩子可以查看它是否使用了http2?

英文:

I am working on some scripts to test our infrastructure at various levels. I am trying to make tests to verify functionality for clients both with and without http2. The docs specify how to disable http2 by overriding Transport.TLSNextProto, but I can't find any way to require http2.

Is there a way to require an http request uses http/2 only? Or if not is there any kind of field or hook to see if it used http2 or not?

答案1

得分: 3

你可以使用Response.ProtoAtLeast(2, 0)来检查它是否是在版本2以上。参见:https://golang.org/pkg/net/http/#Response.ProtoAtLeast

英文:

You can use Response.ProtoAtLeast(2, 0) to check if it came in over version 2. See: https://golang.org/pkg/net/http/#Response.ProtoAtLeast

huangapple
  • 本文由 发表于 2017年5月8日 08:14:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/43838049.html
匿名

发表评论

匿名网友

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

确定